Explore documentation

Authentication

Choose how to connect your application and look after its credentials.

Use a JWT token for a user session, or an API key with limited permissions to connect your server to Esus. For access delegated by a person, see the SMART on FHIR flow further down.

Keep credentials private. The values on this page are fictional. Keep API keys and refresh tokens on your server, out of source control and browser code. Grant only the permissions they need.

Start a user session

JWTs (JSON Web Tokens) are used for user authentication.

Login

curl -X POST https://api.esus.health/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "admin@example.com",
    "password": "SecurePass123!"
  }'

Response:

{
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "8f14e45f-ceea-467a-9f5e-2c1b7a3d9e10",
  "expiresIn": "900s",
  "tokenType": "Bearer"
}

If your account has multi-factor authentication, login returns mfaRequired: true and a temporary mfaToken instead of session tokens. Complete POST /auth/mfa/verify with { "mfaToken": "…", "code": "…" } before querying resources. The temporary token is not an API credential.

Using the Access Token

Include the token in the Authorization header:

curl -X GET https://api.esus.health/fhir/Patient \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Renewing the Token

Access tokens expire after 15 minutes (900 seconds). Use the refresh token to obtain a new access token:

curl -X POST https://api.esus.health/auth/refresh \
  -H "Content-Type: application/json" \
  -d '{
    "refreshToken": "YOUR_REFRESH_TOKEN"
  }'

Connect your server

API Keys are ideal for server-to-server communication.

Create an API Key

curl -X POST https://api.esus.health/api-keys \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production Server",
    "scopes": ["Patient.read", "Observation.read", "Observation.create"]
  }'

Response (HTTP 201 Created):

{
  "id": "c1a2e3d4-5b6f-7890-abcd-ef1234567890",
  "name": "Production Server",
  "clientId": "a7b1c2d3e4f56789abcdef0123456789",
  "secret": "3f8c2a105b4e4d8a9c1f2e7a8b6d4f906fa6c1a2e3d4b5c6",
  "scopes": ["Patient.read", "Observation.read", "Observation.create"],
  "active": true,
  "rateLimit": 1000,
  "createdAt": "2026-04-21T10:30:00Z"
}

Both clientId and secret are random hex strings (no prefixes). Save secret immediately — it is returned only once and cannot be retrieved again. expiresAt only appears when you set an expiry.

Using an API Key

Send the credentials in the X-API-Key header as clientId:secret:

curl -X GET https://api.esus.health/fhir/Patient \
  -H "X-API-Key: a7b1c2d3e4f56789abcdef0123456789:3f8c2a105b4e4d8a9c1f2e7a8b6d4f906fa6c1a2e3d4b5c6"

For an app-scoped key, send the app ID in X-App-Id. Send X-Esus-Expected-Organization to check that the credential belongs to the expected organization.

Scope Permissions

Scopes follow the Resource.action pattern. The valid actions are read, create, update, and delete; searches (a GET on the collection) are authorized by read. Use Resource.* for all actions on a resource, or * (on its own, no prefix) for full access.

  • *.read is not valid: the resource wildcard only exists as a bare *.
  • Resource.write grants create, update, and delete. Grant only the individual actions your application needs.
ScopePermission
Patient.readRead and search Patient resources
Patient.createCreate Patients
Patient.updateUpdate Patients
Patient.deleteDelete Patients
Patient.*All Patient operations
*Full access (all resources and actions)

Delegate access with SMART on FHIR

SMART on FHIR is the standard OAuth 2.0 flow for third-party healthcare apps. Use it when your app acts on behalf of an Esus user. The resulting token never grants more than the user already has: scopes narrow that access. Use it for supported FHIR interactions and to verify the integration connection.

Discover the Authorization Server

curl https://api.esus.health/.well-known/smart-configuration

Response (abridged):

{
  "issuer": "https://api.esus.health",
  "authorization_endpoint": "https://api.esus.health/smart/authorize",
  "token_endpoint": "https://api.esus.health/smart/token",
  "token_endpoint_auth_methods_supported": ["client_secret_post"],
  "capabilities": ["launch-ehr", "launch-standalone", "client-public", "client-confidential-symmetric", "context-ehr-patient", "permission-v1", "permission-v2", "permission-patient", "permission-user"],
  "scopes_supported": ["launch", "patient/*.read", "patient/*.write", "patient/*.rs", "patient/*.cruds", "user/*.read", "user/*.write", "user/*.rs", "user/*.cruds"],
  "code_challenge_methods_supported": ["S256"]
}

Step 1: Register Your Application

An organization admin does this. The scopes you register are the most the app can ever request: at authorization, each requested scope must match a registered one exactly (registering patient/*.read does not allow requesting patient/Observation.read). Scopes that do not match are dropped, and if none match the request fails with 400.

curl -X POST https://api.esus.health/smart/apps \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My FHIR App",
    "redirectUris": ["https://myapp.com/callback"],
    "scopes": ["launch", "patient/*.read"],
    "isConfidential": true
  }'

The response includes clientId and clientSecret. The secret is only checked for confidential apps (isConfidential is true by default). Store it: it is shown only once.

Step 2 (optional): Pin a Patient with a Launch

To have the app work on a specific patient (EHR launch), request a launch with the user’s session. It is valid for 10 minutes and can be used once.

curl -X POST https://api.esus.health/smart/launch \
  -H "Authorization: Bearer USER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "client_id": "YOUR_CLIENT_ID", "patient": "3fa85f64-5717-4562-b3fc-2c963f66afa6" }'
{ "launch": "9c1f2e7a8b6d4f90...", "expires_in": 600 }

Step 3: Authorization Request (PKCE)

/smart/authorize is a GET made with the user’s Esus session. PKCE with S256 is mandatory. When everything is valid it responds with a 302 redirect to your redirect_uri carrying code and state.

GET https://api.esus.health/smart/authorize
  ?response_type=code
  &client_id=YOUR_CLIENT_ID
  &redirect_uri=https://myapp.com/callback
  &scope=launch patient/*.read
  &launch=9c1f2e7a8b6d4f90...
  &state=random-state-string
  &code_challenge=BASE64URL(SHA256(code_verifier))
  &code_challenge_method=S256

Step 4: Token Exchange

The code is valid for 10 minutes and can be used once.

curl -X POST https://api.esus.health/smart/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=authorization_code" \
  -d "code=AUTH_CODE" \
  -d "redirect_uri=https://myapp.com/callback" \
  -d "client_id=YOUR_CLIENT_ID" \
  -d "client_secret=YOUR_CLIENT_SECRET" \
  -d "code_verifier=YOUR_CODE_VERIFIER"

Response:

{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "launch patient/*.read",
  "patient": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}

patient is present only when a launch was used. There is no refresh token: authorize again when it expires.

Step 5: Use the Token

curl https://api.esus.health/fhir/Observation?patient=3fa85f64-5717-4562-b3fc-2c963f66afa6 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

SMART Scopes

Both v1 (.read, .write, .*) and v2 (.c, .r, .u, .d, .s combined in that order, e.g. .rs or .cruds) scopes are accepted, for one resource (patient/Observation.read) or all of them (patient/*.read).

ScopeAccess
patient/*.readRead the launched patient’s resources
patient/*.writeCreate, update and delete that patient’s resources
user/*.readRead what the user can already read
user/*.writeWrite what the user can already write
launchAccepted, but it does not control the context: patient is returned whenever the authorization used a launch
  • With patient/ scopes and no launch, the token reaches no patient data.
  • Patient/{id}/$everything requires a *.read scope.
  • No id_token or refresh tokens are issued: openid, fhirUser and offline_access are not supported.

Quick Reference

MethodWhen to UseHeader
JWTUser sessions, internal appsAuthorization: Bearer token
API KeyServer to server, CLI toolsX-API-Key: clientId:secret
SMART on FHIRThird-party apps, user-delegated accessAuthorization: Bearer access_token

Next Steps

With access ready, let’s work with Patient: the resource that describes a person receiving care.