Struct gotham_middleware_jwt::JWTMiddleware
source · pub struct JWTMiddleware<T> { /* private fields */ }
Expand description
This middleware verifies that JSON Web Token
credentials, provided via the HTTP Authorization
header, are extracted, parsed, and validated
according to best practices before passing control
to middleware beneath this middleware for a given
mount point.
Requests that lack the Authorization
header are
returned with the Status Code 400: Bad Request
.
Tokens that fail validation cause the middleware
to return Status Code 401: Unauthorized
.
Implementations
sourceimpl<T> JWTMiddleware<T>where
T: for<'de> Deserialize<'de> + Send + Sync,
impl<T> JWTMiddleware<T>where
T: for<'de> Deserialize<'de> + Send + Sync,
sourcepub fn new(secret: &'static str) -> Self
pub fn new(secret: &'static str) -> Self
Creates a JWTMiddleware instance from the provided secret, which, by default, uses HS256 as the crypto scheme.
sourcepub fn validation(self, validation: Validation) -> Self
pub fn validation(self, validation: Validation) -> Self
Create a new instance of the middleware by appending new validation constraints.
Trait Implementations
sourceimpl<T> Middleware for JWTMiddleware<T>where
T: for<'de> Deserialize<'de> + Send + Sync + 'static,
impl<T> Middleware for JWTMiddleware<T>where
T: for<'de> Deserialize<'de> + Send + Sync + 'static,
sourcefn call<Chain>(self, state: State, chain: Chain) -> Box<HandlerFuture>where
Chain: FnOnce(State) -> Box<HandlerFuture>,
fn call<Chain>(self, state: State, chain: Chain) -> Box<HandlerFuture>where
Chain: FnOnce(State) -> Box<HandlerFuture>,
Entry point to the middleware. To pass the request on to the application, the middleware
invokes the
chain
function with the provided state
. Read moresourceimpl<T> NewMiddleware for JWTMiddleware<T>where
T: for<'de> Deserialize<'de> + RefUnwindSafe + Send + Sync + 'static,
impl<T> NewMiddleware for JWTMiddleware<T>where
T: for<'de> Deserialize<'de> + RefUnwindSafe + Send + Sync + 'static,
type Instance = JWTMiddleware<T>
type Instance = JWTMiddleware<T>
The type of
Middleware
created by the NewMiddleware
.sourcefn new_middleware(&self) -> Result<Self::Instance>
fn new_middleware(&self) -> Result<Self::Instance>
Create and return a new
Middleware
value.Auto Trait Implementations
impl<T> RefUnwindSafe for JWTMiddleware<T>where
T: RefUnwindSafe,
impl<T> Send for JWTMiddleware<T>where
T: Send,
impl<T> Sync for JWTMiddleware<T>where
T: Sync,
impl<T> Unpin for JWTMiddleware<T>where
T: Unpin,
impl<T> UnwindSafe for JWTMiddleware<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more