Skip to main content

ApiKeyBackend

Trait ApiKeyBackend 

Source
pub trait ApiKeyBackend: Send + Sync {
    // Required methods
    fn put(&self, key: &ApiKey);
    fn get(&self, id: &str) -> Option<ApiKey>;
    fn delete(&self, id: &str) -> bool;
    fn list_for_user(&self, user_id: &str) -> Vec<ApiKey>;
    fn touch(&self, id: &str, now: u64);
}
Expand description

Storage backend for API keys. Same pluggable pattern as sessions

  • magic codes — in-memory default, runtime injects SQLite/Postgres.

Required Methods§

Source

fn put(&self, key: &ApiKey)

Source

fn get(&self, id: &str) -> Option<ApiKey>

Source

fn delete(&self, id: &str) -> bool

Source

fn list_for_user(&self, user_id: &str) -> Vec<ApiKey>

All keys for a given user, used by management endpoints.

Source

fn touch(&self, id: &str, now: u64)

Update last_used_at. Called on every successful auth — must be cheap. Implementations are free to debounce (write at most once per minute, etc.) but the in-memory default writes straight through.

Implementors§