pub struct AuthMiddleware { /* private fields */ }Expand description
Authentication Middleware
Validates incoming requests for authentication requirements. Acts as the second layer in the security middleware pipeline.
Implementations§
Source§impl AuthMiddleware
impl AuthMiddleware
Sourcepub fn from_config(config: AuthConfig) -> Self
pub fn from_config(config: AuthConfig) -> Self
Create a new authentication middleware from configuration.
Emits a warning when required = true but no signing key is configured,
because JWT signature verification will be disabled in that case.
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create middleware with permissive settings (authentication optional)
Sourcepub fn strict() -> Self
pub fn strict() -> Self
Create middleware with strict settings (authentication required, short expiry)
Sourcepub fn validate_request(
&self,
req: &AuthRequest,
) -> Result<AuthenticatedUser, SecurityError>
pub fn validate_request( &self, req: &AuthRequest, ) -> Result<AuthenticatedUser, SecurityError>
Validate authentication in a request.
Performs validation checks in order:
- Extract token from Authorization header
- Validate token signature (if signing key configured)
- Check token expiry (exp claim)
- Validate issuer/audience claims (if configured)
- Extract required claims (sub)
- Extract optional claims (scope, aud, iss)
§Errors
Returns SecurityError::AuthRequired if no Authorization header or
token is missing. Returns SecurityError::InvalidToken if the token
signature, expiry, issuer, or audience is invalid. Returns
SecurityError::TokenMissingClaim if a required claim is absent.
Sourcepub const fn config(&self) -> &AuthConfig
pub const fn config(&self) -> &AuthConfig
Get the underlying configuration
Trait Implementations§
Source§impl Clone for AuthMiddleware
impl Clone for AuthMiddleware
Source§fn clone(&self) -> AuthMiddleware
fn clone(&self) -> AuthMiddleware
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AuthMiddleware
impl RefUnwindSafe for AuthMiddleware
impl Send for AuthMiddleware
impl Sync for AuthMiddleware
impl Unpin for AuthMiddleware
impl UnsafeUnpin for AuthMiddleware
impl UnwindSafe for AuthMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more