Auth Module Architecture
The auth code lives in two crates. octofhir-auth holds the logic and the storage traits.
octofhir-auth-postgres implements those traits on PostgreSQL. octofhir-server mounts the HTTP
routes and the middleware.
For how to use it, see Authentication.
Overview
Section titled “Overview”┌──────────────────────────────────────────────────────────────┐│ octofhir-server ││ Axum router → auth middleware → FHIR handlers │└──────────────┬───────────────────────────────────────────────┘ ▼┌──────────────────────────────────────────────────────────────┐│ octofhir-auth ││ OAuth 2.0 server SMART on FHIR UDAP ││ Token service AccessPolicy engine (matcher, QuickJS) │└──────────────┬───────────────────────────────────────────────┘ ▼┌──────────────────────────────────────────────────────────────┐│ octofhir-auth-postgres ││ Clients, users, roles, sessions, tokens, policies │└──────────────────────────────────────────────────────────────┘Modules
Section titled “Modules”Module (octofhir-auth) |
Purpose |
|---|---|
config |
The [auth] configuration |
oauth |
Authorization, client authentication, PKCE, sessions |
http |
Handlers for the /auth/* endpoints |
token |
JWT signing and validation, introspection, revocation |
smart |
SMART scopes, launch context, discovery |
policy |
AccessPolicy engine, policy cache and reload |
federation |
External identity provider types, client JWKS cache |
udap |
UDAP registration, see UDAP |
middleware, extractors |
Axum extractors such as BearerAuth and AdminAuth |
audit |
Security audit events |
storage |
Storage traits |
OAuth 2.0
Section titled “OAuth 2.0”- Authorization code flow with PKCE
- Client credentials flow for backend services
- Refresh token flow
- Password grant, for clients that list it, such as the built-in
octofhir-uiclient - Token introspection (RFC 7662) and revocation (RFC 7009)
SMART on FHIR
Section titled “SMART on FHIR”- SMART v2 scopes (
patient/*.rs,user/*.cruds,system/*.rs), and v1 suffixes - EHR launch and standalone launch
- Patient and encounter context
- OpenID Connect
Tokens
Section titled “Tokens”- JWT with RS256, RS384 and ES384
- Lifetimes from
[auth.oauth] - See JWT Key Persistence for signing keys
AccessPolicy Engine
Section titled “AccessPolicy Engine”A request first passes the SMART scope check. Matching AccessPolicy resources are then evaluated in
priority order. A policy uses the allow or deny engine, or a QuickJS script. Policies are kept in a
cache that reloads when an AccessPolicy changes. See Access Policies.
External Identity Providers
Section titled “External Identity Providers”IdentityProvider resources name OpenID Connect, OAuth 2.0 and SAML 2.0 providers.
http/federated.rs runs the sign-in: PKCE and a nonce for OAuth, the ID token checked against the
provider’s keys, SAML responses checked in federation/saml.rs; then it finds or creates the user
and applies the role rules. The IdentityProviderHook keeps the registered providers in step with the
resources, so a change needs no restart. See Identity Providers.
Security-relevant events are written as FHIR AuditEvent resources.
Configuration
Section titled “Configuration”Settings are in octofhir.toml under [auth]:
[auth]issuer = "http://localhost:8888"
[auth.oauth]access_token_lifetime = "1h"refresh_token_lifetime = "90d"grant_types = ["authorization_code", "client_credentials", "refresh_token"]
[auth.signing]algorithm = "RS384"
[auth.smart]launch_ehr_enabled = truelaunch_standalone_enabled = truepublic_clients_allowed = trueopenid_enabled = true
[auth.policy]quickjs_enabled = trueSee Configuration for the rest.