pub struct TokenInfo {
pub token_id: String,
pub subject: Option<String>,
pub scopes: Vec<Scope>,
pub expires_at: Option<SystemTime>,
pub metadata: HashMap<String, String>,
}Expand description
Information about a validated token
Fields§
§token_id: StringToken identifier (the token itself for CPSK, or extracted ID for JWT/PASETO)
subject: Option<String>Subject identifier (user, device, or service)
scopes: Vec<Scope>Scopes granted by this token
expires_at: Option<SystemTime>When the token expires (if any)
metadata: HashMap<String, String>Additional metadata
Implementations§
Source§impl TokenInfo
impl TokenInfo
Sourcepub fn new(token_id: String, scopes: Vec<Scope>) -> Self
pub fn new(token_id: String, scopes: Vec<Scope>) -> Self
Create a new TokenInfo with minimal fields
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if this token is expired
Sourcepub fn has_scope(&self, action: Action, address: &str) -> bool
pub fn has_scope(&self, action: Action, address: &str) -> bool
Check if the token allows the given action on the given address
Sourcepub fn with_subject(self, subject: impl Into<String>) -> Self
pub fn with_subject(self, subject: impl Into<String>) -> Self
Set the subject
Sourcepub fn with_expires_at(self, expires_at: SystemTime) -> Self
pub fn with_expires_at(self, expires_at: SystemTime) -> Self
Set the expiration time
Sourcepub fn with_expires_in(self, duration: Duration) -> Self
pub fn with_expires_in(self, duration: Duration) -> Self
Set the expiration from a duration
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TokenInfo
impl RefUnwindSafe for TokenInfo
impl Send for TokenInfo
impl Sync for TokenInfo
impl Unpin for TokenInfo
impl UnwindSafe for TokenInfo
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