app.auth.deps¶
FastAPI dependencies: the authenticated principal and permissions.
Identity comes from verified token claims only; no user is stored.
Real (RS256) and dev (HS256) tokens produce their claims through
app.auth.tokens.verify_token() and then share this module’s
mapping (principal_from_claims()) and authorization
(require_permission()).
Claim mapping:
issuer/subject–iss/sub(required).display–name, elsepreferred_username, elsesub.email–email, unless the token saysemail_verified: false(thenNone).roles– the list of strings at the dottedADRIANO_OIDC_ROLES_CLAIMpath (defaultroles; Keycloak:realm_access.roles). A missing path or a non-list value yields no roles; non-string items are ignored.
Permissions come from the rbac section loaded at startup
(app.auth.rbac); no configuration means no permissions.
Public API: Principal, principal_from_claims(),
get_oidc_validator(), get_principal(),
get_permissions(), require_permission().
- class app.auth.deps.Principal(issuer, subject, display, email, roles)¶
Bases:
objectThe authenticated caller, from verified token claims.
- Parameters:
- app.auth.deps.get_oidc_validator(settings=Depends(dependency=<functools._lru_cache_wrapper object>, use_cache=True, scope=None))¶
FastAPI dependency: the OIDC validator, if OIDC is configured.
Tests override this to inject mocked discovery and keys.
- Parameters:
settings (
Settings) – Application settings.- Return type:
- Returns:
The cached validator, or
None.
- app.auth.deps.get_permissions(principal=Depends(dependency=<function get_principal>, use_cache=True, scope=None), runtime=Depends(dependency=<function get_catalog_runtime>, use_cache=True, scope=None))¶
FastAPI dependency: the caller’s permissions.
- Parameters:
principal (
Principal) – The authenticated caller.runtime (
CatalogRuntime|None) – Startup state (rbacsection).
- Return type:
- Returns:
Granted permissions (none without configuration).
- app.auth.deps.get_principal(credentials=Depends(dependency=<fastapi.security.http.HTTPBearer object>, use_cache=True, scope=None), settings=Depends(dependency=<functools._lru_cache_wrapper object>, use_cache=True, scope=None), oidc=Depends(dependency=<function get_oidc_validator>, use_cache=True, scope=None))¶
FastAPI dependency: authenticate the bearer token.
Synchronous on purpose: FastAPI runs it in a worker thread, so the (rare) discovery/JWKS fetch never blocks the event loop.
- Parameters:
credentials (
HTTPAuthorizationCredentials|None) – TheAuthorization: Bearercredentials.settings (
Settings) – Application settings.oidc (
OidcValidator|None) – The OIDC validator, if configured.
- Return type:
- Returns:
The principal.
- Raises:
AuthUnavailableError – If authentication is not configured or the IdP is unreachable (HTTP 503).
AuthenticationError – If the token is missing or not acceptable (HTTP 401).
- app.auth.deps.require_permission(permission)¶
Build a dependency that requires permission.
Use as
Depends(require_permission(Permission.READ)).- Parameters:
permission (
Permission) – The required permission.- Return type:
- Returns:
A dependency returning the authenticated principal.