pub struct ApiKeyRecord {
pub id: Uuid,
pub key_hash: String,
pub key_prefix: String,
pub user_id: String,
pub name: String,
pub scopes: Vec<String>,
pub created_at: DateTime<Utc>,
pub expires_at: Option<DateTime<Utc>>,
pub last_used_at: Option<DateTime<Utc>>,
pub revoked: bool,
}Expand description
An API key record stored in the database
Fields§
§id: UuidUnique key ID (not the actual key)
key_hash: StringArgon2id hash of the API key (includes salt, never store plaintext)
key_prefix: StringFirst 12 characters of key for identification (safe to show)
user_id: StringUser ID this key belongs to
name: StringHuman-readable name for the key
scopes: Vec<String>Scopes/permissions granted
created_at: DateTime<Utc>When the key was created
expires_at: Option<DateTime<Utc>>When the key expires (None = never)
last_used_at: Option<DateTime<Utc>>When the key was last used
revoked: boolWhether the key is revoked
Implementations§
Source§impl ApiKeyRecord
impl ApiKeyRecord
Sourcepub fn new(
user_id: &str,
name: &str,
scopes: Vec<String>,
expires_in_days: Option<u32>,
) -> (Self, String)
pub fn new( user_id: &str, name: &str, scopes: Vec<String>, expires_in_days: Option<u32>, ) -> (Self, String)
Create a new API key record (does not store it) Returns (record, plaintext_key) - the plaintext key is only available once!
Sourcepub fn hash_key(key: &str) -> String
pub fn hash_key(key: &str) -> String
Hash an API key for secure storage using Argon2id with random salt Returns the PHC-formatted hash string (includes salt)
Sourcepub fn verify_key(plaintext_key: &str, stored_hash: &str) -> bool
pub fn verify_key(plaintext_key: &str, stored_hash: &str) -> bool
Verify a plaintext key against a stored Argon2id hash Uses constant-time comparison to prevent timing attacks
Trait Implementations§
Source§impl Clone for ApiKeyRecord
impl Clone for ApiKeyRecord
Source§fn clone(&self) -> ApiKeyRecord
fn clone(&self) -> ApiKeyRecord
Returns a duplicate of the value. Read more
1.0.0 · 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 ApiKeyRecord
impl Debug for ApiKeyRecord
Source§impl<'de> Deserialize<'de> for ApiKeyRecord
impl<'de> Deserialize<'de> for ApiKeyRecord
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 ApiKeyRecord
impl RefUnwindSafe for ApiKeyRecord
impl Send for ApiKeyRecord
impl Sync for ApiKeyRecord
impl Unpin for ApiKeyRecord
impl UnwindSafe for ApiKeyRecord
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
Converts
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>
Converts
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