pub struct AuthToken {
pub token_id: String,
pub user_id: String,
pub access_token: String,
pub refresh_token: Option<String>,
pub token_type: 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 metadata: TokenMetadata,
}Expand description
Represents an authentication token with all associated metadata.
Fields§
§token_id: StringUnique token identifier
user_id: StringUser identifier this token belongs to
access_token: StringThe actual token string (JWT, opaque token, etc.)
refresh_token: Option<String>Optional refresh token
token_type: StringToken type (Bearer, etc.)
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: StringAuthentication method used to obtain this token
client_id: Option<String>Client ID that requested this token
metadata: TokenMetadataAdditional 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 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.
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>,
Deserialize this value from the given Serde deserializer. Read more
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<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