pub struct ApiKeyStore { /* private fields */ }Implementations§
Source§impl ApiKeyStore
impl ApiKeyStore
pub fn new() -> Self
pub fn with_backend(backend: Box<dyn ApiKeyBackend>) -> Self
Sourcepub fn create(
&self,
user_id: String,
name: String,
scopes: Option<String>,
expires_at: Option<u64>,
) -> (String, ApiKey)
pub fn create( &self, user_id: String, name: String, scopes: Option<String>, expires_at: Option<u64>, ) -> (String, ApiKey)
Mint a new API key. Returns (plaintext, ApiKey) — the
plaintext MUST be shown to the user exactly once and never
stored anywhere on the server. The ApiKey is what’s
persisted (with secret_hash not the secret).
Wire format: pk.<id>.<secret> — the id is embedded so
verification is one DB lookup, not a table scan. Hash-only
schemes that store no plaintext id make verification O(N).
. separator (not _) so it survives the URL-safe base64
alphabet that base64url uses for both id and secret bodies.
Sourcepub fn verify(&self, token: &str) -> Result<ApiKey, ApiKeyVerifyError>
pub fn verify(&self, token: &str) -> Result<ApiKey, ApiKeyVerifyError>
Verify a plaintext token. Touches last_used_at on success
so the management UI can show “last used 5m ago”.
touch is debounced to once-per-minute per key to avoid a
write storm on hot keys (one DB write per request was a real
contention source under load).