ApiKeyStore

Trait ApiKeyStore 

Source
pub trait ApiKeyStore: Send + Sync {
    // Required methods
    fn create<'life0, 'life1, 'async_trait>(
        &'life0 self,
        record: &'life1 ApiKeyRecord,
    ) -> Pin<Box<dyn Future<Output = Result<(), ApiKeyError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn find_by_hash<'life0, 'life1, 'async_trait>(
        &'life0 self,
        hash: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<ApiKeyRecord>, ApiKeyError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn find_and_verify_key<'life0, 'life1, 'async_trait>(
        &'life0 self,
        plaintext_key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<ApiKeyRecord>, ApiKeyError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn find_by_user<'life0, 'life1, 'async_trait>(
        &'life0 self,
        user_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ApiKeyRecord>, ApiKeyError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn record_usage<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = Result<(), ApiKeyError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn revoke<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = Result<(), ApiKeyError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = Result<(), ApiKeyError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn rotate<'life0, 'async_trait>(
        &'life0 self,
        old_key_id: Uuid,
        expires_in_days: Option<u32>,
    ) -> Pin<Box<dyn Future<Output = Result<(ApiKeyRecord, String), ApiKeyError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

API key storage trait

Required Methods§

Source

fn create<'life0, 'life1, 'async_trait>( &'life0 self, record: &'life1 ApiKeyRecord, ) -> Pin<Box<dyn Future<Output = Result<(), ApiKeyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Store a new API key

Source

fn find_by_hash<'life0, 'life1, 'async_trait>( &'life0 self, hash: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<ApiKeyRecord>, ApiKeyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Find a key by its hash (for legacy SHA-256 compatibility)

Source

fn find_and_verify_key<'life0, 'life1, 'async_trait>( &'life0 self, plaintext_key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<ApiKeyRecord>, ApiKeyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Find and verify a key using Argon2 Recommended approach: extract key ID from prefix for O(1) lookup

Source

fn find_by_user<'life0, 'life1, 'async_trait>( &'life0 self, user_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ApiKeyRecord>, ApiKeyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Find all keys for a user

Source

fn record_usage<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), ApiKeyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Update last_used_at timestamp

Source

fn revoke<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), ApiKeyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Revoke a key

Source

fn delete<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), ApiKeyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete a key

Source

fn rotate<'life0, 'async_trait>( &'life0 self, old_key_id: Uuid, expires_in_days: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<(ApiKeyRecord, String), ApiKeyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Rotate a key: creates a new key and revokes the old one

§Arguments
  • old_key_id - The ID of the key to rotate
  • expires_in_days - TTL for the new key (default: 90 days)
§Returns
  • (new_record, plaintext_key) - The new record and plaintext key (shown once!)

Implementors§