You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(auth): add JWT Bearer token authentication support
Extends api.auth to accept Auth0 JWT Bearer tokens alongside existing
cookie-based sessions. Bearer auth is opt-in via AUTH_JWT_ENABLED and
AUTH_JWT_AUDIENCE; each require_* dependency tries Bearer first, then
falls back to cookie. Adds JWKS fetching with per-domain TTL cache.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: src/aignostics_foundry_core/AGENTS.md
+10-11Lines changed: 10 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ This file provides an overview of all modules in `aignostics_foundry_core`, thei
11
11
|**models**| Shared output format enum |`OutputFormat` StrEnum with `YAML` and `JSON` values for use in CLI and API responses |
12
12
|**process**| Current process introspection |`ProcessInfo`, `ParentProcessInfo` Pydantic models and `get_process_info()` for runtime process metadata; `SUBPROCESS_CREATION_FLAGS` for subprocess creation |
13
13
|**api.exceptions**| API exception hierarchy and FastAPI handlers |`ApiException` (500), `NotFoundException` (404), `AccessDeniedException` (401); `api_exception_handler`, `unhandled_exception_handler`, `validation_exception_handler` for FastAPI registration |
|**api.core**| Versioned API router and FastAPI factory |`VersionedAPIRouter` (tracks all created instances), `API_TAG_*` constants, `create_public/authenticated/admin/internal/internal_admin_router` factories, `build_api_metadata`, `build_versioned_api_tags`, `build_root_api_tags`, `get_versioned_api_instances(versions, build_metadata=None, *, context=None)`, `init_api()`|
16
16
|**api**| Consolidated API sub-package | Re-exports all public symbols from `api.exceptions`, `api.auth`, and `api.core`; import any API symbol directly from `aignostics_foundry_core.api`|
@@ -108,22 +108,21 @@ This file provides an overview of all modules in `aignostics_foundry_core`, thei
108
108
109
109
### api.auth
110
110
111
-
**Auth0 authentication and authorization FastAPI dependencies**
111
+
**Auth0 authentication and authorization FastAPI dependencies (cookie + Bearer JWT)**
112
112
113
-
-**Purpose**: Provides Auth0 cookie-based session authentication dependencies for FastAPI routes. All project-specific settings (org ID, role claim) are loaded from `AuthSettings` whose env prefix is configurable at instantiation.
113
+
-**Purpose**: Provides Auth0 cookie-based session and JWT Bearer token authentication dependencies for FastAPI routes. Each `require_*` dependency accepts either an Auth0 session cookie **or** a Bearer JWT — Bearer is tried first, cookie is the fallback.
114
114
-**Key Features**:
115
-
-`AuthSettings(OpaqueSettings)` — uses the active FoundryContext to derive both the env prefix (`{ctx.env_prefix}AUTH_`) and the env file list (`ctx.env_file`). Fields: `internal_org_id` (required `str`; identifies the internal organization), `auth0_role_claim` (required `str`; JWT claim name for role). Both fields are mandatory — no defaults are provided.
115
+
-`AuthSettings(OpaqueSettings)` — uses the active FoundryContext (`{ctx.env_prefix}AUTH_`). Key fields: `cookie_enabled` (`AUTH_COOKIE_ENABLED`; new primary name), `enabled` (`AUTH_ENABLED`; deprecated alias for `cookie_enabled`, kept for backwards compat), `jwt_enabled` (`AUTH_JWT_ENABLED`; opt-in Bearer JWT auth), `jwt_audience` (`AUTH_JWT_AUDIENCE`; required when `jwt_enabled=True`), `domain`, `client_id`, `client_secret`, `internal_org_id`, `role_claim`, `session_secret`, `session_expiration`.
116
116
-`UnauthenticatedError(Exception)` — raised when a user session is missing or invalid
117
117
-`ForbiddenError(ApiException)` — `status_code = 403`; raised when user lacks required role or org membership
118
118
-`get_auth_client(request)` — retrieves `AuthClient` from `request.app.state.auth_client`; raises `RuntimeError` if not configured
119
-
-`get_user(request, _cookie)` — async FastAPI dependency; returns user dict from Auth0 session or `None`; validates expiry; sets Sentry user context
120
-
-`require_authenticated` — dependency: requires a valid session
121
-
-`require_admin` — dependency: requires admin role
-`get_user(request, _cookie, _bearer)` — async FastAPI dependency; tries Bearer JWT first (when `jwt_enabled=True`), falls back to cookie; returns user dict or `None`; sets Sentry user context
120
+
-`require_authenticated`, `require_admin`, `require_internal`, `require_internal_admin` — FastAPI dependencies; each accepts both cookie and Bearer schemes in OpenAPI
0 commit comments