Expand description
Dual-mode bearer/JWT/cookie auth middleware shipped as a [tower::Layer].
Consumers integrate with .layer(AuthLayer::new(...)) rather than wrapping
a free authenticate_request function in a closure-of-7-args. The
middleware writes an AuthContext into request extensions on success,
returns an AuthError-shaped 401 response on failure, and (for cookie
mode + browser GETs) optionally redirects to a configured login path so the
configured OAuth/OIDC flow can establish a session.
Precedence (matches the legacy lab middleware):
Authorization: Bearer <token>matches the static bearer (constant-time compare) -> grantsstatic_token_scopes.Authorization: Bearer <token>validates as a JWT issued by the local auth state (audience + issuer enforced insidecrate::jwt::SigningKeys::validate_access_token_with_issuer) -> grants the JWT-claim scopes.- (Optional, when
AuthLayerwas constructed withallow_session_cookie = true.) Browser session cookie matches a row in the auth store, with CSRF enforced for non-GET/HEAD/OPTIONS. - Otherwise, browser GET requests with
Accept: text/htmlare redirected to the configured login path; everything else returns 401 withWWW-Authenticate: Bearer resource_metadata=....
Structs§
- Auth
Layer - Tower layer that authenticates inbound requests and writes
AuthContextinto request extensions. - Auth
Service - Service half of
AuthLayer. Forwards toinnerafter a successful authentication; otherwise short-circuits with a 401 / redirect response.
Functions§
- parse_
bearer_ token - Parse a single
Authorization: Bearer <token>header value, returningNonefor malformed or non-Bearer schemes. - tokens_
equal - Constant-time byte comparison for static-bearer matching (prevents timing-based prefix leakage).
Type Aliases§
- Actor
KeyDeriver - Closure-erased actor-key derivation hook.