pub struct JwtContext<T>(/* private fields */);Expand description
JWT authentication context. Implements Tower Layer (decodes
tokens from requests) and FromRequestParts (via FromRef) for use in handlers.
Construct with JwtContext::builder.
Implementations§
Source§impl JwtContext<()>
impl JwtContext<()>
Sourcepub fn builder() -> JwtContextBuilder
pub fn builder() -> JwtContextBuilder
Create a JwtContextBuilder to configure keys, extraction method, and validation.
Source§impl<T: Serialize> JwtContext<T>
impl<T: Serialize> JwtContext<T>
Sourcepub fn encode_token(&self, data: &T) -> Result<String>
pub fn encode_token(&self, data: &T) -> Result<String>
Encode claims into a signed JWT string.
Encode claims into a signed JWT and wrap it in a Set-Cookie cookie.
Only works when the context is configured to extract from a cookie.
Return an expired cookie that clears the JWT cookie on the client.
Trait Implementations§
Source§impl<T> Clone for JwtContext<T>
impl<T> Clone for JwtContext<T>
Source§impl<S, U> FromRequestParts<S> for JwtContext<U>
impl<S, U> FromRequestParts<S> for JwtContext<U>
Auto Trait Implementations§
impl<T> Freeze for JwtContext<T>
impl<T> RefUnwindSafe for JwtContext<T>where
T: RefUnwindSafe,
impl<T> Send for JwtContext<T>
impl<T> Sync for JwtContext<T>
impl<T> Unpin for JwtContext<T>
impl<T> UnsafeUnpin for JwtContext<T>
impl<T> UnwindSafe for JwtContext<T>where
T: RefUnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.