Authentication
How people sign in (Keycloak OpenID Connect with PKCE), how systems get tokens (client credentials, or private_key_jwt for external systems and facility devices), and how module tokens work.
The network separates who is calling (a person or a registered system) from what they may see (decided on every request by consent, care relationship, role and jurisdiction). Authentication answers only the first question.
People: OpenID Connect with PKCE (Keycloak)
Browser sign-in for people uses Keycloak (realm ohn, public client ohn-web) with the authorisation code flow and PKCE (S256). The platform runs the flow server-side so that the PKCE verifier never reaches the browser:
- The page calls
POST /api/ohn/v1/platform/oidc/startwith{ "purpose": "sign_in", "return_to": "/app" }. The platform creates thestate, thenonceand the PKCE verifier, keeps them server-side (state and nonce as keyed hashes, the verifier sealed), and answers{ "authorization_url", "purpose", "expires_in": 600 }. - The browser goes to
authorization_url(scopeopenid,code_challenge_method=S256). Keycloak authenticates the person: password plus a one-time code (TOTP, 6 digits, 30 s) or a passkey. - Keycloak redirects to the platform’s sign-in page with
codeandstate, which callsPOST /api/ohn/v1/platform/oidc/callbackwith{ "code", "state" }. - The platform consumes the state (single use, 10 minutes), exchanges the code with the verifier, verifies the ID token (issuer, audience,
azp, signature RS256/PS256/ES256, expiry, nonce), checks that a second factor was used (amr), maps the Keycloak subject to the platform person (ohn_principal_idclaim) and opens a platform session.
The answer is { "access_token", "token_type": "Bearer", "session_id", "expires_in", "principal_id", "provider", "purpose", "step_up_max_age" }. The access_token is an opaque platform session token, not the Keycloak token; only its keyed hash is stored. Sessions last one hour by default (configurable between 5 minutes and 12 hours). oidc/start and oidc/callback are limited to 30 requests per minute per client address.
GET /api/ohn/v1/platform/identity tells a client which provider a deployment uses (keycloak, or platform for synthetic deployments that sign in with a username and code).
Step-up for sensitive actions
Some actions need a fresh, strong authentication. The client calls oidc/start with "purpose": "step_up" (and its session token); Keycloak is asked to authenticate again (prompt=login, max_age=0). The new authentication must be the same person, newer than the request, use a second factor (amr contains otp, hwk, swk, mfa or sc) and carry an accepted acr. Step-up stays valid for 5 minutes by default.
Sign-out
Keycloak back-channel logout (POST /api/ohn/v1/platform/oidc/backchannel-logout) closes the platform sessions of that Keycloak session.
Systems: client credentials (OHN-38)
Registered applications get tokens with the OAuth 2.0 client credentials grant. The body is JSON:
POST /api/ohn/v1/oauth/token
Content-Type: application/json
Idempotency-Key: 6b1f2c3e-...
{ "grant_type": "client_credentials", "client_id": "<uuid>", "client_secret": "<secret>", "scope": "orders.read orders.write" }
client_idis a UUID;client_secretis at least 32 characters; every requested scope must be allowed for the client.- The answer is
{ "access_token", "token_type": "Bearer", "expires_in": 3600, "scope", "session_id" }. - Every failure answers
401 invalid_client, andgrant_typeother thanclient_credentialsanswers422. - Introspect a token with
POST /api/ohn/v1/sessions/introspect{ "token" }and theX-Device-Attestationheader of the client’s sandbox credentials (a missing or different value answers403 device_binding_mismatch). Discovery:/.well-known/openid-configuration.
Module tokens
Each network service accepts short-lived tokens issued for it. A signed-in session exchanges its session token at POST /api/ohn/v1/platform/tokens with { "module": "ohn-11" } and receives { "module", "access_token", "expires_in", "role", "purpose", "issuer": "gateway" }. Module tokens last at most 15 minutes, less for sensitive services (no longer than the step-up window). The SDKs do this exchange for you (GatewayTokens).
Current status. Exchanging a machine session (client credentials) for module tokens is not enabled for partner accounts yet: the platform answers
no_partner_account. Until it is, use client credentials to obtain and introspect tokens in the sandbox, and exercise module APIs as a signed-in developer in the developer workspace. For triage (OHN-61) and pre-consultation (OHN-62), registered external systems and facility devices already get gateway tokens through theprivate_key_jwtroute below (see Triage and pre-consultation APIs). This page will change when partner module access is released.
External systems and facility devices: private_key_jwt
Third-party triage systems, FHIR clients and facility devices (waiting-room kiosks, waiting-room displays, edge nodes) do not use a client secret. Each one is a Keycloak confidential client that signs in with private_key_jwt (RFC 7523, the SMART Backend Services pattern): the system keeps its private key, and the network stores only its public keys.
Who registers what
| Client | Role | Registered by | Where |
|---|---|---|---|
| Third-party triage system | external_triage_system | A network administrator (fresh second factor) | Network console → External systems |
| FHIR client | fhir_client | A network administrator (fresh second factor) | Network console → External systems |
| Waiting-room kiosk | kiosk_device | The facility’s own administrator (fresh second factor) | POST /api/ohn/v1/platform/team/devices |
| Waiting-room display | display_device | The facility’s own administrator | POST /api/ohn/v1/platform/team/devices |
| Edge node (offline batches) | edge_sync | The facility’s own administrator | POST /api/ohn/v1/platform/team/devices |
A registration takes a name, one role and public keys only: a JWKS document (1 to 5 keys, each with a kid; RSA 2048 bits or more for RS256/PS256, or EC P-256 for ES256) or an https JWKS URL. External systems are bound to one facility chosen by the network administrator. Devices are always bound to the enrolling administrator’s own facility. The answer gives the client id, the token endpoint and the exchange endpoint. Install the private key on the system or device itself, never in the platform.
1. Get a Keycloak token
Sign a short JWT with your private key and send it in a client-credentials request to the realm’s token endpoint:
issandsub: your client id;aud: the token endpoint URL;- a unique
jtifor every request (a reusedjtiis refused); expat most 60 seconds ahead.
curl -s -X POST "$OHN/auth/realms/ohn/protocol/openid-connect/token" \
-d grant_type=client_credentials \
-d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
--data-urlencode "client_assertion=$ASSERTION"
// Node.js 18+: build the client assertion (ES256). The key here is generated on the spot: a synthetic example only.
import { generateKeyPairSync, randomUUID, sign } from 'node:crypto';
const { privateKey } = generateKeyPairSync('ec', { namedCurve: 'P-256' }); // in real use: your own key (a KeyObject or a PEM string)
const b64 = (o) => Buffer.from(JSON.stringify(o)).toString('base64url');
export function clientAssertion(clientId, tokenEndpoint, kid, key = privateKey) {
const now = Math.floor(Date.now() / 1000);
const head = b64({ alg: 'ES256', typ: 'JWT', kid });
const body = b64({ iss: clientId, sub: clientId, aud: tokenEndpoint, jti: randomUUID(), iat: now, exp: now + 60 });
const sig = sign('sha256', Buffer.from(`${head}.${body}`), { key, dsaEncoding: 'ieee-p1363' });
return `${head}.${body}.${sig.toString('base64url')}`;
}
2. Exchange it for a gateway token
POST /api/ohn/v1/platform/external-tokens
Authorization: Bearer <Keycloak access token>
Content-Type: application/json
{ "audience": "ohn-61", "purpose": "triage_external_intake" }
The platform checks the Keycloak token, that the client is registered and active and that it holds its role, then answers { "access_token", "token_type": "Bearer", "expires_in", "audience", "role", "purpose", "organization_id" }. The gateway token lasts at most 300 seconds and never longer than the Keycloak token. Every issue and every refusal is audited.
| Role | ohn-61 purposes | ohn-62 purposes |
|---|---|---|
external_triage_system | triage_external_intake (default), triage_interop | preconsult_interop |
fhir_client | triage_interop | preconsult_interop |
kiosk_device | triage_reception | preconsult_capture |
display_device | waiting_room_display | (refused) |
edge_sync | triage_sync | (refused) |
Any other pair answers 422 not_allowed_for_role. An edge node’s batch operations are attributed to the on-shift person named in each operation’s performed_by; see Triage and pre-consultation APIs.
Revoking
Revocation takes effect at once: the exchange refuses the client even while its Keycloak token is still valid, and Keycloak stops issuing new tokens. A facility administrator revokes a lost device with POST /api/ohn/v1/platform/team/devices/{id}/revoke and a reason (no second-factor prompt, so it can be done quickly); network administrators revoke from the console. Revocation is final: register a new client to resume.
Keys and verification
Gateway-issued tokens are signed; the public keys are at /api/ohn/v1/platform/jwks and /.well-known/jwks.json.
Good practice
- Keep client secrets in a secret manager; rotate them from the developer workspace.
- Never put a person’s one-time-code secret in software. Username-and-code sign-in exists only for synthetic demo accounts.
- Request the smallest set of scopes you need.