pub struct TokenValidator { /* private fields */ }Expand description
Token validator for JWT access tokens
Implementations§
Source§impl TokenValidator
impl TokenValidator
Sourcepub fn new(secret: String) -> TokenValidator
pub fn new(secret: String) -> TokenValidator
Create a new token validator with a secret
Sourcepub fn get_secret(&self) -> &str
pub fn get_secret(&self) -> &str
Get the secret (for testing)
Sourcepub fn with_decoding_key(self, key: DecodingKey) -> TokenValidator
pub fn with_decoding_key(self, key: DecodingKey) -> TokenValidator
Set the decoding key for JWT verification
Sourcepub fn with_audience<T>(self, audience: T) -> TokenValidatorwhere
T: ToString,
pub fn with_audience<T>(self, audience: T) -> TokenValidatorwhere
T: ToString,
Set required audience
Sourcepub fn with_issuer<T>(self, issuer: T) -> TokenValidatorwhere
T: ToString,
pub fn with_issuer<T>(self, issuer: T) -> TokenValidatorwhere
T: ToString,
Set required issuer
Sourcepub async fn validate_token(
&self,
token: &str,
) -> Result<TokenClaims, AuthError>
pub async fn validate_token( &self, token: &str, ) -> Result<TokenClaims, AuthError>
Validate a JWT access token
Sourcepub fn validate_audience(
&self,
claims: &TokenClaims,
expected_audience: &str,
) -> Result<(), AuthError>
pub fn validate_audience( &self, claims: &TokenClaims, expected_audience: &str, ) -> Result<(), AuthError>
Validate token audience specifically (RFC 8707)
Sourcepub fn validate_scopes(
&self,
claims: &TokenClaims,
required_scopes: &[String],
) -> Result<(), AuthError>
pub fn validate_scopes( &self, claims: &TokenClaims, required_scopes: &[String], ) -> Result<(), AuthError>
Validate required scopes
Trait Implementations§
Source§impl Clone for TokenValidator
impl Clone for TokenValidator
Source§fn clone(&self) -> TokenValidator
fn clone(&self) -> TokenValidator
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 Default for TokenValidator
impl Default for TokenValidator
Source§fn default() -> TokenValidator
fn default() -> TokenValidator
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TokenValidator
impl RefUnwindSafe for TokenValidator
impl Send for TokenValidator
impl Sync for TokenValidator
impl Unpin for TokenValidator
impl UnwindSafe for TokenValidator
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