app.auth.tokens¶
Bearer-token validation: pick the validator by the unverified alg.
Per module-dev-auth-bypass the validator is selected from the
token’s unverified header, never by trying validators in turn:
RS256-> the OIDC/JWKS validator (app.auth.oidc); never the dev validator.HS256-> the dev validator (app.auth.dev), only whenADRIANO_DEV_SHARED_SECRETis set; otherwise 401.anything else (
none,HS512,ES256…) -> 401.
Both paths return verified claims that feed the same
app.auth.deps.principal_from_claims() mapping.
Semantics: HTTP 503 (AuthUnavailableError) means
the server can authenticate nobody right now (no mechanism configured,
or the IdP is unreachable); HTTP 401
(AuthenticationError) means this request’s
credentials are not acceptable.
Public API: AuthStatus, auth_status(),
ensure_configured(), verify_token().
- class app.auth.tokens.AuthStatus(*values)¶
Bases:
StrEnumWhich token validators are configured (reported by
/healthz).- OIDC = 'oidc'¶
- DEV = 'dev'¶
- OIDC_AND_DEV = 'oidc+dev'¶
- UNCONFIGURED = 'unconfigured'¶
- app.auth.tokens.auth_status(settings)¶
Describe the configured token validators.
- Parameters:
settings (
Settings) – Application settings.- Return type:
- Returns:
The status.
- app.auth.tokens.ensure_configured(settings)¶
Refuse requests when no token validator is configured.
- Parameters:
settings (
Settings) – Application settings.- Raises:
AuthUnavailableError – If neither OIDC nor the dev secret is configured.
- Return type:
- app.auth.tokens.verify_token(token, settings, oidc)¶
Validate a bearer token with the validator its
algselects.- Parameters:
token (
str) – Raw bearer token.settings (
Settings) – Application settings.oidc (
OidcValidator|None) – The OIDC validator,Nonewhen OIDC is not configured.
- Return type:
- Returns:
The verified claims.
- Raises:
AuthenticationError – If the token is not acceptable.
AuthUnavailableError – If the IdP cannot be reached.