pub struct Authn { /* private fields */ }Expand description
The authenticators the authn middleware consults: an optional
Authorization: Bearer path (JWT or static token) and an optional opaque
X-API-Key path running alongside it (ADR 0006). At least one is set — the
middleware is never mounted when both are absent (see AuthConfig).
Build it with Authn::bearer_only or Authn::with_api_key, then mount
with axum::middleware::from_fn_with_state(authn_state, authn). A
composition root rarely builds it directly: the router_with_* builders take
an AuthConfig and derive the right Authn from it.
Implementations§
Source§impl Authn
impl Authn
Sourcepub fn bearer_only(bearer: Arc<dyn Authenticator>) -> Self
pub fn bearer_only(bearer: Arc<dyn Authenticator>) -> Self
Authenticate only Authorization: Bearer (no X-API-Key path). An
X-API-Key header, if any, is ignored and the request falls through to the
bearer/anonymous path.
Sourcepub fn with_api_key(
bearer: Arc<dyn Authenticator>,
api_key: Arc<dyn Authenticator>,
) -> Self
pub fn with_api_key( bearer: Arc<dyn Authenticator>, api_key: Arc<dyn Authenticator>, ) -> Self
Authenticate X-API-Key against api_key first, then
Authorization: Bearer against bearer. The two are independent
mechanisms; a request presenting neither is the anonymous principal.