pub struct JwtManager {
pub config: JwtConfig,
/* private fields */
}Expand description
JWT token manager
Fields§
§config: JwtConfigImplementations§
Source§impl JwtManager
impl JwtManager
Sourcepub fn new(config: JwtConfig) -> Result<Self, JwtConfigError>
pub fn new(config: JwtConfig) -> Result<Self, JwtConfigError>
Create a new JWT manager
Sourcepub fn generate_token(
&self,
user_id: impl Into<String>,
) -> Result<String, TokenError>
pub fn generate_token( &self, user_id: impl Into<String>, ) -> Result<String, TokenError>
Generate a new access token
Sourcepub fn generate_token_with_claims(
&self,
claims: Claims,
) -> Result<String, TokenError>
pub fn generate_token_with_claims( &self, claims: Claims, ) -> Result<String, TokenError>
Generate a new access token with custom claims
Sourcepub fn generate_refresh_token(
&self,
user_id: impl Into<String>,
) -> Result<String, TokenError>
pub fn generate_refresh_token( &self, user_id: impl Into<String>, ) -> Result<String, TokenError>
Generate a new refresh token
Sourcepub fn generate_token_pair(
&self,
user_id: impl Into<String>,
) -> Result<TokenPair, TokenError>
pub fn generate_token_pair( &self, user_id: impl Into<String>, ) -> Result<TokenPair, TokenError>
Generate a token pair (access + refresh)
Sourcepub fn validate_token(&self, token: &str) -> Result<Claims, TokenError>
pub fn validate_token(&self, token: &str) -> Result<Claims, TokenError>
Validate and decode a token
Sourcepub fn refresh_access_token(
&self,
refresh_token: &str,
) -> Result<TokenPair, TokenError>
pub fn refresh_access_token( &self, refresh_token: &str, ) -> Result<TokenPair, TokenError>
Refresh an access token using a refresh token
Sourcepub fn decode_unverified(&self, token: &str) -> Result<Claims, TokenError>
pub fn decode_unverified(&self, token: &str) -> Result<Claims, TokenError>
Decode token without validation (use with caution)
Sourcepub fn extract_token_from_header(header_value: &str) -> Result<&str, TokenError>
pub fn extract_token_from_header(header_value: &str) -> Result<&str, TokenError>
Extract token from Authorization header value
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JwtManager
impl RefUnwindSafe for JwtManager
impl Send for JwtManager
impl Sync for JwtManager
impl Unpin for JwtManager
impl UnwindSafe for JwtManager
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> 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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request