Blog

    SMART Backend Services: Client Assertions, JWKS Key Rotation and System Scopes

    By GauravNovember 27, 20269 mins read
    On this page

    Not every FHIR client has a person behind it. Nightly exports, population health jobs and integration engines call FHIR servers on their own, and they need a way to prove who they are without a password sitting in a config file.

    SMART Backend Services is the HL7 answer for that case. This guide is for engineers and security leads implementing it: what goes into the signed assertion, how to publish and rotate keys, which system scopes to request, how token lifetime works and how to test the whole flow before a server rejects it in production.

    How does SMART Backend Services authorization work?

    Building FHIR services that run without a user?

    See how we design SMART on FHIR apps and backend services that pass vendor review.

    SMART Backend Services authorization works by having a registered backend client sign a short-lived JWT with its private key, send it to the token endpoint and receive a short-lived access token with system scopes. Agnotic Technologies implements this flow for exports, integrations and other jobs that run without a user.

    No shared secret travels over the network. The server checks the signature against public keys the client published when it registered.

    When should a system use backend services?

    A system should use backend services when it acts on its own authority, with no user signing in, and the server's owner has approved that access in advance. Typical cases are scheduled and bulk work.

    • Bulk exports: population or cohort data pulled on a schedule.
    • Integration engines: services that move data between systems around the clock.
    • Analytics and quality jobs: measure calculations over many patients.
    • Monitoring: checks that confirm an API is up and returning valid data.

    If a person is present and their permissions should limit the data, use a user-facing SMART launch instead. Backend access is broad, so it needs a stronger reason.

    What goes into the signed client assertion?

    The signed client assertion is a JWT that identifies the client, names the token endpoint as its audience, expires within minutes and carries a unique id. The server rejects it if any of those checks fail.

    SMART Backend Services flow: a backend service signs a JWT client assertion with its private key, the token endpoint verifies the signature against the client's registered JWK Set and checks the jti and expiry, issues a short-lived access token with system scopes, and the service calls the FHIR server and requests a new token when it expires, with a key publishing lane

    In SMART asymmetric client authentication, the client signs a JWT whose iss and sub are its client_id and whose exp is no more than five minutes in the future; clients shall support both RS384 and ES384, and servers check that a jti has not been used before by that client within the JWT's allowed lifetime.

    • Header: the algorithm, the kid of the signing key and, optionally, the jku pointing at your registered JWK Set URL.
    • iss and sub: your client_id, exactly as the server registered it.
    • aud: the token endpoint URL, copied from the server's discovery document.
    • exp and jti: a near expiry and a fresh random id for every request.

    Build a new assertion for every token request. Reusing one breaks the jti rule and fails as a replay.

    Publishing keys with a JWK Set URL

    Publish your public keys at a stable HTTPS address that the server can read without authentication, and give that address at registration. The private keys never leave your secrets store.

    SMART requires authorization servers to accept client public keys both as a JWK Set URL and as a JWK Set given at registration, and calls the URL strongly preferred because it lets a client rotate its own keys by updating the hosted content.

    • Hosting: a small static endpoint or object store behind TLS, separate from the service that signs.
    • Content: only public keys, each with a kid and the algorithm it is used with.
    • Caching: a Cache-Control header so servers know how long to keep your keys.
    • Private keys: stored in a key vault or hardware module, with signing done there where possible.

    How do you rotate keys without downtime?

    Rotate keys by publishing the new public key beside the old one, switching signing to the new key after servers have had time to fetch it, then removing the old key. Both keys sit in the JWK Set during the overlap.

    • Step 1, add: generate the new key pair and publish its public key with a new kid.
    • Step 2, wait: allow at least the cache period you advertise before signing with it.
    • Step 3, switch: sign new assertions with the new key and its kid.
    • Step 4, retire: remove the old public key once no server could still need it.

    Rotate on a schedule and practice it. A rotation done for the first time during a key compromise is the one most likely to cause an outage.

    Which system scopes should a backend request?

    A backend should request only the system scopes its job needs, such as read and search on the specific resource types it uses. Broad scopes make the client a larger target and slow down approval.

    • Name resources: list each resource type instead of a wildcard.
    • Limit actions: read and search for exports, with write only where the job truly creates data.
    • Split clients: give unrelated jobs separate client registrations and scopes.
    • Check grants: compare the scopes in the token response with what you asked for.

    Servers may grant fewer scopes than requested. Fail loudly when a needed scope is missing, rather than running a partial job that looks complete.

    Token lifetime and renewal

    Backend access tokens are short-lived by design, and the client simply asks for a new one when the current token nears expiry. There is no refresh token step.

    The SMART Backend Services profile says access tokens it issues shall be short-lived, with an expires_in value that should not exceed 300 seconds (five minutes), that refresh tokens should not be issued, and that clients can request new access tokens as needed.

    Cache the token in memory with its expiry, renew a little before it runs out, and share one token across workers in the same process. Requesting a new token for every API call adds load and can trip the server's limits.

    Where backend authorization breaks

    Backend authorization usually breaks at the edges: clocks, keys and configuration. These failures are common and avoidable.

    • Clock drift: the server's clock and yours disagree, so a valid exp looks expired.
    • Wrong audience: aud set to the FHIR base URL instead of the token endpoint.
    • Stale kid: signing with a key the server has not fetched yet after a rotation.
    • Unreachable JWKS: the key URL sits behind a firewall or requires authentication.
    • Secrets in code: private keys checked into a repository or baked into an image.

    Log the server's error response in full, minus tokens. Most token endpoint errors say exactly which check failed.

    A worked example: a nightly quality measure export

    A worked example: a quality analytics vendor needs nightly data from a health system's FHIR server. The vendor registers a backend client with a JWK Set URL and asks for read and search scopes on five resource types.

    Each night the export job reads the discovery document, builds a fresh assertion with a new jti, signs it in the key vault and receives a token. Workers share the token and request a new one shortly before it expires.

    Months later the vendor rotates keys: the new public key is published, signing switches after the advertised cache period, and the old key is removed. The export never misses a night.

    Who owns what?

    Backend access needs owners on both sides, because a failure on either stops the job. Agree them during registration.

    • Client team: key generation, the JWK Set URL, assertion code, token caching and rotation.
    • Security team: key storage, rotation schedule and access to signing operations.
    • Server owner: client registration, scope approval and audit of backend access.
    • Operations: alerts on token failures and the runbook for a suspected key compromise.

    Keep the registration details, scopes, key URL and contacts in a shared record for each server. When a token request fails overnight, the on-call engineer should not have to search old emails for them.

    How do you test backend authorization?

    Test against a reference server or vendor sandbox first, then add automated checks that build and validate assertions in CI. Include the failures you expect servers to reject.

    • Happy path: discovery, assertion, token and a FHIR call in one run.
    • Rejections: an expired exp, a reused jti, a wrong aud and an unknown kid.
    • Rotation drill: two keys published, switch, retire, with no failed calls.
    • Scope check: a token missing a needed scope stops the job with a clear error.

    Run the rotation drill in staging before every planned rotation in production. Keep the test keys separate from production keys, and never copy a production private key into a test environment.

    What are SMART Backend Services best practices?

    Sign a fresh assertion with a new jti for every token request, keep private keys in a vault, and publish public keys at a JWK Set URL with a cache header. Rotate on a schedule with an overlap.

    Request narrow system scopes, check what was granted, cache short-lived tokens and renew before expiry, and log token errors in full without logging tokens.

    How Agnotic can help

    Agnotic implements SMART Backend Services for vendors and health systems: client registration, assertion signing with managed keys, JWK Set hosting, rotation runbooks, scope design and tests against vendor sandboxes. We also build the export and integration jobs that use the tokens.

    Connect your services with SMART on FHIR

    We build SMART launches and backend access that fit each EHR vendor's rules.

    Sources

    Frequently Asked Questions

    It is the HL7 SMART profile for FHIR clients that run without a user. The client authenticates with a signed JWT and receives a short-lived access token with system scopes.

    Talk to an engineer about your project

    Tell us which FHIR servers your jobs call. We will outline registration, key handling and rotation for backend access.