pub struct JwtService { /* private fields */ }Expand description
JWT service struct providing token generation and validation functionality.
Implementations§
Source§impl JwtService
impl JwtService
Sourcepub fn new(
config: JwtConfig,
encoding_key: EncodingKey,
decoding_key: DecodingKey,
validation: Validation,
) -> JwtService
pub fn new( config: JwtConfig, encoding_key: EncodingKey, decoding_key: DecodingKey, validation: Validation, ) -> JwtService
Sourcepub fn get_config(&self) -> &JwtConfig
pub fn get_config(&self) -> &JwtConfig
Sourcepub fn get_encoding_key(&self) -> &EncodingKey
pub fn get_encoding_key(&self) -> &EncodingKey
Sourcepub fn get_decoding_key(&self) -> &DecodingKey
pub fn get_decoding_key(&self) -> &DecodingKey
Sourcepub fn get_validation(&self) -> &Validation
pub fn get_validation(&self) -> &Validation
Source§impl JwtService
Implementation block for JwtService core functionality.
impl JwtService
Implementation block for JwtService core functionality.
Sourcepub fn generate_token<S>(&self, subject: S) -> Result<JwtToken, String>
pub fn generate_token<S>(&self, subject: S) -> Result<JwtToken, String>
Sourcepub fn validate_token<T>(
&self,
token: T,
) -> Result<JwtExtraJwtClaims, JwtValidationError>
pub fn validate_token<T>( &self, token: T, ) -> Result<JwtExtraJwtClaims, JwtValidationError>
Sourcepub fn get_subject_from_token<T>(&self, token: T) -> Result<String, String>
pub fn get_subject_from_token<T>(&self, token: T) -> Result<String, String>
Source§impl JwtService
Implementation block for JwtService with custom claims support.
impl JwtService
Implementation block for JwtService with custom claims support.
Sourcepub fn generate_token_with_claims<U, S>(
&self,
subject: S,
claims: U,
) -> Result<JwtToken, String>
pub fn generate_token_with_claims<U, S>( &self, subject: S, claims: U, ) -> Result<JwtToken, String>
Generates a JWT token with custom claims.
§Arguments
AsRef<str>- The subject (user identifier) to include in the token.Clone + Default + Serialize + for<'de> Deserialize<'de>- The custom claims to include in the token payload.
§Returns
Result<JwtToken, String>- The generated token on success, or an error message on failure.
Sourcepub fn validate_token_with_claims<U, T>(
&self,
token: T,
) -> Result<CustomExtraJwtClaims<U>, JwtValidationError>
pub fn validate_token_with_claims<U, T>( &self, token: T, ) -> Result<CustomExtraJwtClaims<U>, JwtValidationError>
Sourcepub fn generate_token_with_extra_claims<S>(
&self,
subject: S,
extra: HashMap<String, Value>,
) -> Result<JwtToken, String>
pub fn generate_token_with_extra_claims<S>( &self, subject: S, extra: HashMap<String, Value>, ) -> Result<JwtToken, String>
Generates a JWT token with extra custom fields.
§Arguments
AsRef<str>- The subject (user identifier) to include in the token.HashMap<String, Value>- Additional key-value pairs to include in the token payload.
§Returns
Result<JwtToken, String>- The generated token on success, or an error message on failure.
Sourcepub fn validate_token_with_extra_claims<T>(
&self,
token: T,
) -> Result<ExtraJwtClaims, JwtValidationError>
pub fn validate_token_with_extra_claims<T>( &self, token: T, ) -> Result<ExtraJwtClaims, JwtValidationError>
Sourcepub fn get_from_token<T, K>(
&self,
token: T,
field_key: K,
) -> Result<Option<Value>, JwtValidationError>
pub fn get_from_token<T, K>( &self, token: T, field_key: K, ) -> Result<Option<Value>, JwtValidationError>
Trait Implementations§
Source§impl Clone for JwtService
impl Clone for JwtService
Source§fn clone(&self) -> JwtService
fn clone(&self) -> JwtService
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JwtService
impl Debug for JwtService
Auto Trait Implementations§
impl Freeze for JwtService
impl RefUnwindSafe for JwtService
impl Send for JwtService
impl Sync for JwtService
impl Unpin for JwtService
impl UnwindSafe for JwtService
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<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 more