Explore documentation

Best Practices

Security practices for integrating with Esus

Checklist

Authentication

  • Turn on MFA (TOTP) for console accounts, especially admin accounts.
  • In browser apps, use the httpOnly cookies that /auth/login sets instead of storing tokens in localStorage.
  • Keep API keys only on your server: never in frontend code or in the repository.
  • Set expiresAt when you create an API key, and rotate it regularly with POST /api-keys/:id/rotate.
  • For apps acting on behalf of a user, use SMART on FHIR with PKCE.

Authorization

  • Grant the minimum API key scopes (Patient.read, not *). Keys skip consent, so Patient.read reads every patient in the organization.
  • Request only the SMART scopes you need (patient/Observation.read instead of user/*.write).
  • Limit admin to the people who need it: admins skip the consent check.
  • Assign emergency-responder only to people who need break-glass access, and review their events.
  • Review role assignments regularly (GET /roles).

Data and Privacy

  • Send If-Match on every PUT/PATCH when concurrency matters.
  • Record treatment consents only when the patient actually gave them.
  • Do not copy PHI to systems you do not control, and do not write tokens, secrets, or PHI to your logs.
  • Collect only the data you need.

Common Mistakes

1. Storing Tokens in localStorage

// BAD — any XSS can read it
localStorage.setItem('token', accessToken)

// BETTER — /auth/login sets httpOnly cookies (__Host-accessToken / __Host-refreshToken).
// For mutations with a cookie, send X-Requested-With (CSRF protection):
fetch('https://api.esus.health/fhir/Patient', {
  method: 'POST',
  credentials: 'include',
  headers: { 'Content-Type': 'application/fhir+json', 'X-Requested-With': 'XMLHttpRequest' },
  body: JSON.stringify(patient),
})

2. Requesting Broad Scopes

// BAD
scope: 'user/*.write user/*.read'

// GOOD — read-only viewer for one patient
scope: 'launch patient/Patient.read patient/Observation.read'

3. Assuming There Are Automatic Alerts

Esus does not send alerts for emergency overrides or denied access. Query the log periodically and build alerts in your own system:

# Emergency overrides on Patient
curl "https://api.esus.health/admin/audit?entity=Patient%5Bemergency%5D" \
  -H "Authorization: Bearer ADMIN_TOKEN"

# Denied access since a given date
curl "https://api.esus.health/admin/audit?outcome=failure&date=ge2026-01-01" \
  -H "Authorization: Bearer ADMIN_TOKEN"

4. Unclear API Key Names

Use descriptive names so you know what to revoke if a key is compromised:

{ "name": "prod-ehr-integration-2026", "scopes": ["Patient.read", "Observation.read"] }

Incident Response

If a token or API key is compromised:

# 1. Console session: revoke ALL of the user's sessions and refresh tokens
curl -X POST https://api.esus.health/auth/logout-all \
  -H "Authorization: Bearer USER_TOKEN"

# 2a. API key you still use: rotate it and revoke the old secret NOW (no grace period)
curl -X POST https://api.esus.health/api-keys/KEY_ID/rotate \
  -H "Authorization: Bearer ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "graceHours": 0 }'

# 2b. API key you no longer need: delete it
curl -X DELETE https://api.esus.health/api-keys/KEY_ID \
  -H "Authorization: Bearer ADMIN_TOKEN"

# 3. Review what that user did
curl "https://api.esus.health/admin/audit/user/USER_ID" \
  -H "Authorization: Bearer ADMIN_TOKEN"

Without graceHours: 0, rotation keeps the old secret valid for 24 hours. Do not rely on the default rotation when the key has been compromised. Rotation returns a new key (new id, clientId, and secret): update your server with both values.

To review a key’s activity, filter with agent=apikey@<clientId>.

For SMART tokens, deactivate or delete the app (PUT/DELETE /smart/apps/:id): its tokens stop working immediately.

Periodic Reviews

  • Review the audit log (GET /admin/audit), especially failure events and [emergency] access.
  • Rotate API keys and remove keys you no longer use (GET /api-keys shows lastUsedAt).
  • Review role assignments and who has admin.
  • Review active treatment consents and set unnecessary ones to inactive.