pub struct PersonalAccessToken {
pub id: TokenId,
pub user_id: UserId,
pub name: String,
pub token_hash: String,
pub token_prefix: String,
pub scopes: Vec<TokenScope>,
pub expires_at: Option<u64>,
pub last_used_at: Option<u64>,
pub created_at: u64,
}Expand description
A personal access token for authentication.
Fields§
§id: TokenIdUnique token ID.
user_id: UserIdUser who owns this token.
name: StringUser-provided name/description.
token_hash: StringArgon2id hash of the full token (prefix + secret).
token_prefix: StringFirst 8 characters for quick lookup.
scopes: Vec<TokenScope>Scopes granted to this token.
expires_at: Option<u64>Optional expiration timestamp.
last_used_at: Option<u64>Last time the token was used.
created_at: u64When the token was created.
Implementations§
Source§impl PersonalAccessToken
impl PersonalAccessToken
Sourcepub fn generate(
id: TokenId,
user_id: UserId,
name: String,
scopes: Vec<TokenScope>,
expires_at: Option<u64>,
) -> Result<(Self, String)>
pub fn generate( id: TokenId, user_id: UserId, name: String, scopes: Vec<TokenScope>, expires_at: Option<u64>, ) -> Result<(Self, String)>
Generate a new token with a random value.
Returns the token struct and the plaintext token value (only shown once).
Sourcepub fn verify(&self, secret: &str) -> Result<()>
pub fn verify(&self, secret: &str) -> Result<()>
Verify a token secret against the stored hash.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the token is expired.
Sourcepub fn has_scope(&self, required: TokenScope) -> bool
pub fn has_scope(&self, required: TokenScope) -> bool
Check if the token has a specific scope.
Sourcepub fn to_response(&self, plaintext: Option<&str>) -> TokenResponse
pub fn to_response(&self, plaintext: Option<&str>) -> TokenResponse
Convert to a response (without the hash).
Trait Implementations§
Source§impl Clone for PersonalAccessToken
impl Clone for PersonalAccessToken
Source§fn clone(&self) -> PersonalAccessToken
fn clone(&self) -> PersonalAccessToken
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PersonalAccessToken
impl Debug for PersonalAccessToken
Source§impl<'de> Deserialize<'de> for PersonalAccessToken
impl<'de> Deserialize<'de> for PersonalAccessToken
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 PersonalAccessToken
impl RefUnwindSafe for PersonalAccessToken
impl Send for PersonalAccessToken
impl Sync for PersonalAccessToken
impl Unpin for PersonalAccessToken
impl UnsafeUnpin for PersonalAccessToken
impl UnwindSafe for PersonalAccessToken
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