pub struct TokenManager { /* private fields */ }Expand description
Token manager for creating, validating, and managing tokens.
Implementations§
Source§impl TokenManager
impl TokenManager
Sourcepub fn new_hmac(
secret: &[u8],
issuer: impl Into<String>,
audience: impl Into<String>,
) -> Self
pub fn new_hmac( secret: &[u8], issuer: impl Into<String>, audience: impl Into<String>, ) -> Self
Create a new token manager with HMAC key.
Sourcepub fn new_rsa(
private_key: &[u8],
public_key: &[u8],
issuer: impl Into<String>,
audience: impl Into<String>,
) -> Result<Self>
pub fn new_rsa( private_key: &[u8], public_key: &[u8], issuer: impl Into<String>, audience: impl Into<String>, ) -> Result<Self>
Create a new token manager with RSA keys.
Sourcepub fn with_default_lifetime(self, lifetime: Duration) -> Self
pub fn with_default_lifetime(self, lifetime: Duration) -> Self
Set the default token lifetime.
Sourcepub fn create_jwt_token(
&self,
user_id: impl Into<String>,
scopes: Vec<String>,
lifetime: Option<Duration>,
) -> Result<String>
pub fn create_jwt_token( &self, user_id: impl Into<String>, scopes: Vec<String>, lifetime: Option<Duration>, ) -> Result<String>
Create a new JWT token.
Sourcepub fn validate_jwt_token(&self, token: &str) -> Result<JwtClaims>
pub fn validate_jwt_token(&self, token: &str) -> Result<JwtClaims>
Validate and decode a JWT token.
Sourcepub fn create_auth_token(
&self,
user_id: impl Into<String>,
scopes: Vec<String>,
auth_method: impl Into<String>,
lifetime: Option<Duration>,
) -> Result<AuthToken>
pub fn create_auth_token( &self, user_id: impl Into<String>, scopes: Vec<String>, auth_method: impl Into<String>, lifetime: Option<Duration>, ) -> Result<AuthToken>
Create a complete authentication token with JWT.
Sourcepub fn validate_auth_token(&self, token: &AuthToken) -> Result<()>
pub fn validate_auth_token(&self, token: &AuthToken) -> Result<()>
Validate an authentication token.
Sourcepub fn refresh_token(&self, token: &AuthToken) -> Result<AuthToken>
pub fn refresh_token(&self, token: &AuthToken) -> Result<AuthToken>
Refresh a token (create a new one with extended lifetime).
Sourcepub fn extract_token_info(&self, token: &str) -> Result<TokenInfo>
pub fn extract_token_info(&self, token: &str) -> Result<TokenInfo>
Extract token information from a JWT.
Auto Trait Implementations§
impl Freeze for TokenManager
impl RefUnwindSafe for TokenManager
impl Send for TokenManager
impl Sync for TokenManager
impl Unpin for TokenManager
impl UnwindSafe for TokenManager
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