JWT Authorization — QIDO-RS / WADO-RS
The QIDO-RS and WADO-RS read interfaces support study-scoped access with
Authorization: Bearer viewer JWTs. Authorization is off by default: it is
enabled per deployment by configuring a token-verification key. When enabled,
every QIDO-RS / WADO-RS request must carry a valid viewer token and may only
reach studies named in that token. The same token, with an added capability,
authorizes the PATCH attribute-correction endpoints.
This page describes the mechanism from both a client-implementer and an operator perspective.
Endpoints covered
| Endpoints | Authorization |
|---|---|
QIDO-RS — GET | QUERY /studies, /studies/{study}/series |
Viewer JWT required when enabled |
WADO-RS — all GET | QUERY retrieve endpoints (study, series, instance, frames, metadata, rendered, thumbnail) |
Viewer JWT required when enabled |
Attribute correction — PATCH /studies/{study}, /studies/{study}/series/{series}, /studies/{study}/series/{series}/instances/{instance} |
Viewer JWT with the dicomweb.modify capability; available only when enabled — see Correction authority |
STOW-RS — POST /studies, POST /studies/{study} |
Never gated — ingestion authenticates out-of-band (mTLS proxy) |
The gate is method-agnostic within the read interface: a QUERY request is
handled the same way as the equivalent GET and is subject to the same
bearer-token and study-scope checks. A deployment may additionally disable
GET/HEAD on the read interface, in which case the gate's authentication
still runs first and an authenticated GET is then answered 405 (Method
Not Allowed) with Allow: QUERY — see
The QUERY method.
The viewer token
The viewer JWT is minted by the smart-launch-api service at the end of a SMART on FHIR EHR launch flow. The DICOMweb service holds only the RS256 public half of the signing keypair and verifies tokens offline against it.
Verification is strict. A token must:
- be signed with RS256 (
algmust be RS256) - carry the expected
iss(issuer) claim - carry the expected
aud(audience) claim - not be expired, and not be used before its
nbftime when it has one (see Clock tolerance)
| Claim | Requirement | Purpose |
|---|---|---|
iss |
Must match the configured issuer | Names the trusted token service |
aud |
Must match the configured audience | Names this service |
exp |
Must be in the future | Expiry, enforced within the configured clock tolerance |
nbf |
If present, must not be in the future | Not-before time, enforced within the configured clock tolerance |
sub |
Present | User identifier — audit attribution only |
ehrIss |
Present | EHR issuer that namespaced sub — audit attribution only |
studyInstanceUIDs |
Array of Study Instance UIDs | The authorization scope |
scope |
Optional; a space-separated list of capabilities | Grants operations beyond reading. dicomweb.modify grants attribute correction |
sub and ehrIss take part in no authorization decision. The scope is the
studyInstanceUIDs array; see below.
When enabled in the DICOMweb service, requests to the QIDO-RS or WADO-RS
services must include a valid signed JWT token. This token shall be provided
by including an Authorization header in the standard way:
Authorization: Bearer <jwt-token>
Study scope
The token's studyInstanceUIDs claim lists the Study Instance UIDs the holder
may reach:
- WADO-RS and series search — every endpoint whose path names a Study
Instance UID (
/studies/{study}/...) requires that study to appear in the token's scope. A valid token naming a different study is refused with403 (Forbidden). - Study search (
/studies) — results are intersected with the token's scope: only studies the token grants can be returned. - Wildcard — a scope containing the literal
'*'grants every study. The token is still required, but no per-study restriction applies. - Empty scope — grants nothing. Study search returns an empty array, and
direct study access is refused with
403. An empty scope is an authorization outcome, not an error.
Correction authority
Reading a study and correcting it are separate grants. A
PATCH request must carry a token that passes the checks
above, has a scope claim whose space-separated list includes
dicomweb.modify, and names the study in studyInstanceUIDs — the '*'
wildcard does not grant a correction. Otherwise the request is refused with
403 (Forbidden).
Status codes
When authorization is enabled:
| Code | Meaning | Response body |
|---|---|---|
401 (Unauthorized) |
No Authorization: Bearer header, a malformed one, or a token that is invalid or expired (bad signature, wrong iss/aud, wrong algorithm, past exp, future nbf) |
{"error": "Unauthorized"} |
403 (Forbidden) |
A valid token that does not grant the requested study — for PATCH, one that does not name the study, or whose scope is '*' |
{"error": "Study not in scope"} |
403 (Forbidden) |
PATCH only: a valid token without the dicomweb.modify capability |
{"error": "Insufficient scope: dicomweb.modify required"} |
A malformed Authorization header — missing token, extra segments — is
rejected rather than salvaged.
Examples
Authenticated request
curl "http://localhost:3000/studies?PatientID=PATIENT001" \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9. ..." \
-H "Accept: application/dicom+json"
curl "http://localhost:3000/studies/1.2.840.../series/1.2.840.../instances/1.2.840.../metadata" \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9. ..." \
-H "Accept: application/dicom+json"
Missing or invalid token
HTTP/1.1 401 Unauthorized
Content-Type: application/json
{"error":"Unauthorized"}
A client receiving 401 should obtain a fresh token from the launch flow and
retry once; persistent 401s indicate a misconfigured issuer, audience, or
signing keypair.
Study outside the token's scope
HTTP/1.1 403 Forbidden
Content-Type: application/json
{"error":"Study not in scope"}
A 403 means the token itself is fine — the client must request a token whose
studyInstanceUIDs includes the study it wants.
Study search under a scoped token
A study search with a valid token returns only studies the token grants, and is indistinguishable in shape from an unscoped search:
curl "http://localhost:3000/studies?StudyDate=20240101-20240131" \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9. ..." \
-H "Accept: application/dicom+json"
Studies the token does not grant are silently excluded. The Warning header
semantics described in QIDO-RS apply as normal.
Client implementer notes
- Send the header on every read request. There is no session or cookie fallback.
- Never place the token in a URL. It is a header value only; URLs reach access logs, proxy logs, and browser history.
- Treat
401and403differently.401asks for a new token;403asks for a different token (one whose scope names the study). - Request tokens with the narrowest useful scope. The scope is the set of studies the session may open; a wildcard token is only needed when the session genuinely browses all studies.
Operating the feature
| Variable | Required | Default | Description |
|---|---|---|---|
JWT_VERIFYING_KEY |
No | — (feature off) | RS256 PEM public key matching the token service's signing key. Its presence turns verification on. \n escape sequences are normalized to real newlines, so both dotenv multi-line and single-line escaped forms work. A value that is not a valid RSA public key — garbage, a private key pasted by mistake, or a key of another algorithm (e.g. EC) — fails startup. The private key must never reach this service. |
JWT_ISSUER |
No | kastoria-smart-launch |
Expected iss claim; a token with any other issuer is rejected with 401 |
JWT_AUDIENCE |
No | kastoria-health |
Expected aud claim; a token with any other audience is rejected with 401 |
JWT_CLOCK_TOLERANCE_SECONDS |
No | 0 |
Seconds of clock difference allowed when checking nbf and exp. An integer from 0 to 30; any other value fails startup. See Clock tolerance. |
- Key distribution is a deployment concern. The keypair is generated and
managed alongside the token service's
JWT_SIGNING_KEY; the operator places the same keypair's public half in this service and its private half in the token service. Startup fails fast on a misconfigured key so a bad deploy surfaces immediately rather than as the first user's401. - With the key unset the feature is off — no header is required and no scope is enforced, and a warning is logged at startup saying so.
- Tokens are PHI-adjacent and are never logged. The service records only
that a request was authenticated and the configured
iss/audconstants; scope denials are logged generically without naming the study or the user. Clients must keep tokens out of their own logs for the same reason.
Clock tolerance
JWT_CLOCK_TOLERANCE_SECONDS sets how many seconds of clock difference are
allowed when a token's nbf (not before) and exp (expiration) times are
checked against the container's clock. It is read by two images, each checking
a different token:
| Image | Token checked |
|---|---|
| kastoria-health | The viewer JWT on QIDO-RS / WADO-RS reads, when verification is on (JWT_VERIFYING_KEY is set) |
| kastoria-smart-launch-api | The ID token the EHR returns during a SMART launch, when it is verified via the EHR's JWKS endpoint |
The default is 0: no clock difference is allowed. The value must be an
integer from 0 to 30; any other value stops the container at startup with
a log message giving the allowed range.
When to set it
If the token issuer's clock and the container's clock differ, valid tokens
are refused. A SMART launch fails with ID Token Validation Failed and the
detail jwt not active or jwt expired; DICOMweb reads return 401. A small
tolerance (for example 30) absorbs that difference. The lasting fix is to
keep both clocks synchronized with NTP.
What the log shows
When a token is refused on nbf or exp, the service logs a warning with the
token's nbf, iat and exp, the server time, the gap between them, and the
tolerance in force. No other token content is logged.
The size of the gap points to the cause:
| Gap | Likely cause |
|---|---|
| Seconds to minutes | Clock difference: synchronize the clocks; the tolerance covers small differences |
| Whole hours | The issuer writes local time as UTC |
| Decades | The issuer writes times in milliseconds instead of seconds |
A gap of whole hours or decades is a fault in the issuer, and no tolerance setting will fix it.
Why the cap is 30 seconds
RFC 7519 §4.1.4–4.1.5 and OpenID Connect Core §2 allow "some small leeway, usually no more than a few minutes, to account for clock skew". The cap keeps that leeway small: a larger value would let expired tokens keep working longer without fixing the clocks.
See also
- QIDO-RS — Search for Instances
- WADO-RS — Retrieve Instances
- PATCH — Correct Stored Attributes — requires the
dicomweb.modifycapability - STOW-RS — Store Instances — exempt from viewer-token authorization by design