Bearer authentication is the default contract for health-api.
Which auth flow to use
| Use case | Endpoint | Notes |
|---|
| Backend or BFF integration | POST /v1/projects/{project_id}/auth/server | Simplest server-side flow. Uses HTTP Basic auth with a confidential client. |
| Mobile or web SDK token exchange | POST /v1/projects/{project_id}/auth/sdk | Exchanges an upstream OIDC token or refresh token. |
| Raw OAuth integration | POST /oauth/token | Canonical OAuth token authority. Form-encoded rather than JSON. |
Recommended server flow
curl -sS -X POST "$BASE_URL/v1/projects/$PROJECT_ID/auth/server" \
-u "$CLIENT_ID:$CLIENT_SECRET" \
-H "Content-Type: application/json" \
-d '{"scope":"users:read daily_records:read ai_summaries:read"}'
Use the returned access token on protected routes:
curl -sS "$BASE_URL/users?limit=10" \
-H "Authorization: Bearer $ACCESS_TOKEN"
Token claims
ONVY access tokens include these core claims:
iss
aud
exp
iat
nbf
jti
project_id
sub
principal_type
scope
If principal_type=user, the token must also include user_id.
Scopes follow this pattern:
<resource>[:namespace]:<action>
Examples:
users:read
daily_records:create
chat_completions:create
admin.oauth_clients:revoke
Convenience endpoints vs canonical OAuth
The JSON convenience endpoints exist to shorten common integration paths:
/auth/server wraps client_credentials
/auth/sdk wraps token exchange and refresh flows
/oauth/token remains the canonical token endpoint when you need raw grant-level control or direct OAuth interoperability.
Do not build new integrations on X-API-Key. The internal API-key shim remains only for migration-safe compatibility.