pub struct ApiKeyAuthenticator { /* private fields */ }Expand description
An opaque API-key → Principal map with revocation: the X-API-Key
counterpart to TokenAuthenticator, sitting behind the same
Authenticator trait so a transport treats it like any other bearer path.
An API key is a long-lived opaque secret a service presents instead of an
interactive OIDC/JWT login — never a JWT (it carries no claims; the Principal
and its scopes are what the key was registered with). The two mechanisms run
side by side: seiva-http’s middleware reads X-API-Key against this, and
Authorization: Bearer against the JWT path.
§Hash at rest, revocation
A key is stored only as its SHA-256 digest, exactly like
TokenAuthenticator — the clear secret never sits in process memory, and the
digest-keyed lookup leaks only pre-image-resistant bytes under a timing
side-channel. revoke drops a key by its digest; a revoked or
never-registered key authenticates to nothing (InvalidToken), so rejection is
the default. An empty map denies every request — zero trust out of the box.
Implementations§
Source§impl ApiKeyAuthenticator
impl ApiKeyAuthenticator
Sourcepub fn new() -> ApiKeyAuthenticator
pub fn new() -> ApiKeyAuthenticator
A new, empty authenticator. On its own it rejects every key.
Sourcepub fn with_key(
self,
key: impl AsRef<str>,
principal: Principal,
) -> ApiKeyAuthenticator
pub fn with_key( self, key: impl AsRef<str>, principal: Principal, ) -> ApiKeyAuthenticator
Register one key → principal (the scopes the key grants), builder-style.
The key is stored as its SHA-256 digest, never in clear.
Sourcepub fn insert(&mut self, key: impl AsRef<str>, principal: Principal)
pub fn insert(&mut self, key: impl AsRef<str>, principal: Principal)
Register one key → principal in place (stored as a SHA-256 digest).
Trait Implementations§
Source§impl Authenticator for ApiKeyAuthenticator
impl Authenticator for ApiKeyAuthenticator
Source§impl Clone for ApiKeyAuthenticator
impl Clone for ApiKeyAuthenticator
Source§fn clone(&self) -> ApiKeyAuthenticator
fn clone(&self) -> ApiKeyAuthenticator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more