Authentication
How people, API clients and services authenticate to the engine, and how the engine's license is checked.
On this page
The engine has three kinds of callers: people using the UI, API clients (scripts, CI jobs, other systems), and the engine's own services. Each authenticates differently.
People
Sign-in is on whenever ENGINE_AUTH_SECRET is set. Every page except /sign-in then needs a session.
- Email and password, then a 6-digit code the engine emails. The code lasts 10 minutes, works once and allows 5 tries.
- An authenticator app, if the person enrolled one, instead of the emailed code. Each code works once: a second use in the same 30-second window is refused. Recovery codes are single-use too.
- Google Workspace sign-in, for the domains in
ENGINE_ALLOWED_DOMAINS. The Workspace account's 2-Step Verification is the second factor. - Single sign-on with your organization's identity provider over OIDC or SAML 2.0 (Entra ID, Okta, Ping, AD FS, Keycloak). The IdP's groups set the role, and people in no mapped group are refused. See Single sign-on.
Sessions end after 60 minutes without activity, and 12 hours after sign-in at most (Session length). Create people with the CLI that ships in the engine image:
create-engine-user admin@example.test --role admin
create-engine-user admin@example.test --reset-password
create-engine-user admin@example.test --disable
create-engine-user ops@example.test --role operator --workspace production:viewer--workspace SLUG[:ROLE] makes the person a member of that workspace, with that role there. You can repeat it. A new non-admin created without it joins the default workspace.
Roles
| Role | Can |
|---|---|
viewer | read ids, statuses, ACKs, timings and errors. Never message content, and never reveal a secret |
operator | also read messages, change workflows, adapter profiles, mappings, code tables and triggers, and run tests and replays |
admin | also change settings, VPN tunnels, workspaces and workspace members, and export the audit log |
A viewer gets messages and executions without the HL7 body, segments, FHIR output, trigger data, step output or patient name. Searching message content is 403 PHI_SEARCH_FORBIDDEN, and field-value counts are 403 PHI_FORBIDDEN. A viewer sees only that a sample or a test case exists. Give operator to anyone who must read messages.
Workspaces
A person works only in the workspaces they are a member of. Their role in a workspace is the lower of their membership role and their engine role, so a workspace admin membership does not make an engine operator an admin. Engine admins are members of every workspace.
- A request for a workspace the person is not a member of is 403
WORKSPACE_FORBIDDEN, and the UI shows No access to this workspace.GET /api/workspaceslists only their workspaces. - Admins manage members at Settings → Users & roles → Members, or with
GET,PUTandDELETE /api/workspaces/{id}/members. Each change is audited asworkspace.member_added,workspace.member_changedorworkspace.member_removed, and reaches signed-in sessions within 10 seconds. - A person created at their first Google sign-in belongs to no workspace until an admin adds them.
- An API client created with
--workspace <slug>works only in that workspace; another is 403WORKSPACE_FORBIDDEN. A client created without--workspacereaches every workspace at its role.
API clients
Machine callers are named API clients. Each has a role and an expiry, and you can revoke it.
create-engine-api-client nightly-sync --role operator --expires 90d
create-engine-api-client nightly-sync --rotate
create-engine-api-client nightly-sync --revoke
create-engine-api-client --listThe key is printed once. The engine stores only its SHA-256 hash. The audit log names the client on every change it makes.
Tokens
Exchange an API client key for a bearer token:
curl -s -X POST "$ENGINE_URL/api/auth/token" \
-H "Content-Type: application/json" \
-d '{"apiKey": "'"$MEDHOOK_API_KEY"'"}'The response is {"token": "...", "expiresAt": "...", "refresh_token": "...", "refreshTokenExpiresAt": "..."}. Send the token as Authorization: Bearer <token>. It lasts 2 hours, or until the client expires. The route allows 5 attempts per minute for each key or refresh token, and 30 per minute per IP address. See POST /api/auth/token.
Refresh tokens
A CI job or scheduled task can keep its access without storing the API key: trade the refresh token for a new token and a new refresh token.
curl -s -X POST "$ENGINE_URL/api/auth/token" \
-H "Content-Type: application/json" \
-d '{"grant_type": "refresh_token", "refresh_token": "'"$MEDHOOK_REFRESH_TOKEN"'"}'- One use each. Every answer carries the next refresh token: store it in place of the one you sent. Sending a used refresh token again revokes every refresh token from the same key exchange, answers
401REFRESH_TOKEN_REUSED, and is audited asrefresh_token.reuse_detected. Exchange the API key again to start over. - Lifetime. 30 days from issue by default, set with
ENGINE_REFRESH_TOKEN_TTL(12h,90d, up to365d), and never past the client's expiry. Each refresh starts a new lifetime. An expired one answers401REFRESH_TOKEN_EXPIRED. - Revocation. Revoking or rotating the API client, in Settings → API clients or with
create-engine-api-client, revokes its refresh tokens (401REFRESH_TOKEN_REVOKED). - Storage and audit. The engine stores only each refresh token's SHA-256 hash. Every issue, use, refusal and revocation is in the audit log under
refresh_token.*, named by the client, and never shows the token.
Root-secret tokens get no refresh token.
Root-secret tokens
{"secret": "<ENGINE_AUTH_SECRET>"} instead of apiKey returns an anonymous admin token. The desktop app's local engine uses it.
Service tokens
Two internal callers use their own tokens, each valid on one route only:
METRICS_TOKEN: Prometheus presents it to/api/metrics.MLLP_ENGINE_TOKEN: the MLLP listener presents it to/api/triggers/mllp.
License keys
The license key is a signed license issued by 1Putt under your contract. You cannot create one yourself. It goes in LICENSE_KEY and looks like mdh_lic_v1.<payload>.<signature>. The payload names your organization, the environment (production or test), whether PHI is allowed, and the contract term end. 1Putt signs it, and the engine checks the signature offline against keys built into the release, so it never has to reach medhook.dev to start or keep running.
- Term end. After the term end the license stays valid through its wind-down (90 days unless your contract says otherwise).
/api/healththen reports the license asgrace. When the wind-down ends, workflows stop. - PHI. Only a
productionlicense with PHI allowed runs PHI workflows. Atestlicense never does. - Revocation. With
LICENSE_REVOCATION_URLset, the engine asks medhook.dev at startup and every 6 hours whether 1Putt revoked the license. Only a clear "revoked" answer ends it. An outage or error changes nothing.
To renew or change a license, ask 1Putt for a new one and replace the LICENSE_KEY secret.
How a license is issued
You never generate a license. 1Putt issues one for each engine you run under your contract.
- Contract. You sign the MedHook contract with 1Putt. It sets the term end and the wind-down.
- BAA. If the engine will handle PHI, you and 1Putt execute the Business Associate Agreement first.
- Issue. 1Putt issues a
productionortestlicense for your organization. It records whether PHI is allowed (only with a BAA on file, and never on atestlicense), the term end, and the wind-down in days (90 unless your contract says otherwise, at most 365). - Hand-over. The signed token is shown once, to 1Putt, when it is issued. medhook.dev keeps only its SHA-256 hash, so nobody can display it again. Your 1Putt deployment engineer gives it to you over a secure channel, or sets it on your engine.
- Install. The token goes in the
LICENSE_KEYsecret. See Install.
1Putt issues every license from your organization's customer record, which holds your contract, your BAA and the engines you run. The license carries your organization's name from that record, and 1Putt links it to the one engine it runs on.
Here is the flow.
sequenceDiagram
participant You as Your organization
participant OnePutt as 1Putt
participant Portal as medhook.dev
participant Engine as Your engine
You->>OnePutt: Contract (and BAA for PHI)
OnePutt->>Portal: Issue a production or test license
Portal-->>OnePutt: Signed token, shown once (only its hash is kept)
OnePutt->>You: Token, over a secure channel
You->>Engine: Set LICENSE_KEY
Engine->>Portal: Revocation check, at startup and every 6 hours, if LICENSE_REVOCATION_URL is setYour medhook.dev account shows each license under Home, read-only: the organization, the environment, whether PHI is allowed, the term end, when the engine last checked in, and whether it is active or revoked. The token itself is never shown there.

To revoke a license, 1Putt marks it revoked. The record is kept, with the time it was revoked, so the history stays complete. An engine with LICENSE_REVOCATION_URL set learns of it at its next check, within 6 hours, and stops at once with no wind-down. Ask 1Putt for a new license before you retire an old one.