pub struct AuthToken {Show 16 fields
pub token_id: String,
pub user_id: String,
pub access_token: String,
pub token_type: Option<String>,
pub subject: Option<String>,
pub issuer: Option<String>,
pub refresh_token: Option<String>,
pub issued_at: DateTime<Utc>,
pub expires_at: DateTime<Utc>,
pub scopes: Vec<String>,
pub auth_method: String,
pub client_id: Option<String>,
pub user_profile: Option<UserProfile>,
pub permissions: Vec<String>,
pub roles: Vec<String>,
pub metadata: TokenMetadata,
}
Expand description
Represents an authentication token with all associated metadata.
Fields§
§token_id: String
Unique token identifier
user_id: String
User identifier this token belongs to
access_token: String
Access token value
token_type: Option<String>
Token type (e.g., “bearer”)
subject: Option<String>
Subject claim
issuer: Option<String>
Token issuer
refresh_token: Option<String>
Optional refresh token
issued_at: DateTime<Utc>
When the token was issued
expires_at: DateTime<Utc>
When the token expires
scopes: Vec<String>
Scopes granted to this token
auth_method: String
Authentication method used to obtain this token
client_id: Option<String>
Client ID that requested this token
user_profile: Option<UserProfile>
User profile data (optional)
permissions: Vec<String>
User’s permissions
roles: Vec<String>
User’s roles
metadata: TokenMetadata
Additional token metadata
Implementations§
Source§impl AuthToken
impl AuthToken
Sourcepub fn new(
user_id: impl Into<String>,
access_token: impl Into<String>,
expires_in: Duration,
auth_method: impl Into<String>,
) -> Self
pub fn new( user_id: impl Into<String>, access_token: impl Into<String>, expires_in: Duration, auth_method: impl Into<String>, ) -> Self
Create a new authentication token.
Sourcepub fn access_token(&self) -> &str
pub fn access_token(&self) -> &str
Get the access token string.
Sourcepub fn expires_at(&self) -> DateTime<Utc>
pub fn expires_at(&self) -> DateTime<Utc>
Get the expiration time.
Sourcepub fn token_value(&self) -> &str
pub fn token_value(&self) -> &str
Get the token value
Sourcepub fn token_type(&self) -> Option<&str>
pub fn token_type(&self) -> Option<&str>
Get the token type
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the token has expired.
Sourcepub fn is_expiring(&self, within: Duration) -> bool
pub fn is_expiring(&self, within: Duration) -> bool
Check if the token is expiring within the given duration.
Sourcepub fn is_revoked(&self) -> bool
pub fn is_revoked(&self) -> bool
Check if the token has been revoked.
Sourcepub fn with_refresh_token(self, refresh_token: impl Into<String>) -> Self
pub fn with_refresh_token(self, refresh_token: impl Into<String>) -> Self
Set the refresh token.
Sourcepub fn with_client_id(self, client_id: impl Into<String>) -> Self
pub fn with_client_id(self, client_id: impl Into<String>) -> Self
Set the client ID.
Sourcepub fn with_scopes(self, scopes: Vec<String>) -> Self
pub fn with_scopes(self, scopes: Vec<String>) -> Self
Set the token scopes.
Sourcepub fn with_metadata(self, metadata: TokenMetadata) -> Self
pub fn with_metadata(self, metadata: TokenMetadata) -> Self
Add metadata to the token.
Sourcepub fn time_until_expiry(&self) -> Duration
pub fn time_until_expiry(&self) -> Duration
Get time until expiration.
Sourcepub fn add_custom_claim(&mut self, key: impl Into<String>, value: Value)
pub fn add_custom_claim(&mut self, key: impl Into<String>, value: Value)
Add a custom claim to the token metadata
Sourcepub fn get_custom_claim(&self, key: &str) -> Option<&Value>
pub fn get_custom_claim(&self, key: &str) -> Option<&Value>
Get a custom claim from the token metadata
Sourcepub fn has_permission(&self, permission: &str) -> bool
pub fn has_permission(&self, permission: &str) -> bool
Check if the token has a specific permission
Sourcepub fn add_permission(&mut self, permission: impl Into<String>)
pub fn add_permission(&mut self, permission: impl Into<String>)
Add a permission to the token
Sourcepub fn with_permissions(self, permissions: Vec<String>) -> Self
pub fn with_permissions(self, permissions: Vec<String>) -> Self
Set the permissions
Sourcepub fn with_roles(self, roles: Vec<String>) -> Self
pub fn with_roles(self, roles: Vec<String>) -> Self
Set the roles
Trait Implementations§
Source§impl<'de> Deserialize<'de> for AuthToken
impl<'de> Deserialize<'de> for AuthToken
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a, R: Row> FromRow<'a, R> for AuthTokenwhere
&'a str: ColumnIndex<R>,
String: Decode<'a, R::Database> + Type<R::Database>,
Option<String>: Decode<'a, R::Database> + Type<R::Database>,
DateTime<Utc>: Decode<'a, R::Database> + Type<R::Database>,
Vec<String>: Decode<'a, R::Database> + Type<R::Database>,
Option<UserProfile>: Decode<'a, R::Database> + Type<R::Database>,
TokenMetadata: Decode<'a, R::Database> + Type<R::Database>,
impl<'a, R: Row> FromRow<'a, R> for AuthTokenwhere
&'a str: ColumnIndex<R>,
String: Decode<'a, R::Database> + Type<R::Database>,
Option<String>: Decode<'a, R::Database> + Type<R::Database>,
DateTime<Utc>: Decode<'a, R::Database> + Type<R::Database>,
Vec<String>: Decode<'a, R::Database> + Type<R::Database>,
Option<UserProfile>: Decode<'a, R::Database> + Type<R::Database>,
TokenMetadata: Decode<'a, R::Database> + Type<R::Database>,
Source§impl TokenToProfile for AuthToken
impl TokenToProfile for AuthToken
Source§async fn to_profile(&self, _provider: &OAuthProvider) -> Result<UserProfile>
async fn to_profile(&self, _provider: &OAuthProvider) -> Result<UserProfile>
Source§impl TokenToProfile for AuthToken
impl TokenToProfile for AuthToken
Source§fn to_profile<'life0, 'life1, 'async_trait>(
&'life0 self,
provider: &'life1 OAuthProvider,
) -> Pin<Box<dyn Future<Output = Result<UserProfile>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn to_profile<'life0, 'life1, 'async_trait>(
&'life0 self,
provider: &'life1 OAuthProvider,
) -> Pin<Box<dyn Future<Output = Result<UserProfile>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn to_profile_with_extractor<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
provider: &'life1 OAuthProvider,
extractor: &'life2 ProfileExtractor,
) -> Pin<Box<dyn Future<Output = Result<UserProfile>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn to_profile_with_extractor<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
provider: &'life1 OAuthProvider,
extractor: &'life2 ProfileExtractor,
) -> Pin<Box<dyn Future<Output = Result<UserProfile>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Auto Trait Implementations§
impl Freeze for AuthToken
impl RefUnwindSafe for AuthToken
impl Send for AuthToken
impl Sync for AuthToken
impl Unpin for AuthToken
impl UnwindSafe for AuthToken
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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>
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>
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