#[non_exhaustive]pub struct JwtAuth<C, D> {
pub force_passed: bool,
pub decoder: D,
pub finders: Vec<Box<dyn JwtTokenFinder>>,
/* private fields */
}Expand description
JWT Authentication middleware for Salvo.
JwtAuth extracts and validates JWT tokens from incoming requests based on the configured
token finders and decoder. If valid, it stores the decoded data in the depot for later use.
§Type Parameters
C- The claims type that will be deserialized from the JWT payload.D- The decoder implementation used to validate and decode the JWT token.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.force_passed: boolWhen set to true, the middleware will allow the request to proceed even if
authentication fails, storing only the authentication state in the depot.
When set to false (default), requests with invalid or missing tokens will be
immediately rejected with appropriate status codes.
decoder: DThe decoder used to validate and decode the JWT token.
finders: Vec<Box<dyn JwtTokenFinder>>A list of token finders that will be used to extract the token from the request. Finders are tried in order until one returns a token.
Implementations§
Source§impl<C, D> JwtAuth<C, D>
impl<C, D> JwtAuth<C, D>
Sourcepub fn force_passed(self, force_passed: bool) -> JwtAuth<C, D>
pub fn force_passed(self, force_passed: bool) -> JwtAuth<C, D>
Sets force_passed value and return Self.
Sourcepub fn decoder_mut(&mut self) -> &mut D
pub fn decoder_mut(&mut self) -> &mut D
Get decoder mutable reference.
Sourcepub fn finders_mut(&mut self) -> &mut Vec<Box<dyn JwtTokenFinder>>
pub fn finders_mut(&mut self) -> &mut Vec<Box<dyn JwtTokenFinder>>
Gets a mutable reference to the extractor list.
Trait Implementations§
Source§impl<C, D> Handler for JwtAuth<C, D>
impl<C, D> Handler for JwtAuth<C, D>
Source§fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
req: &'life1 mut Request,
depot: &'life2 mut Depot,
res: &'life3 mut Response,
ctrl: &'life4 mut FlowCtrl,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
JwtAuth<C, D>: 'async_trait,
fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
req: &'life1 mut Request,
depot: &'life2 mut Depot,
res: &'life3 mut Response,
ctrl: &'life4 mut FlowCtrl,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
JwtAuth<C, D>: 'async_trait,
Source§fn arc(self) -> ArcHandlerwhere
Self: Sized,
fn arc(self) -> ArcHandlerwhere
Self: Sized,
ArcHandler.