Skip to main content

Identity providers

MedBackend validates RS256 JWTs and maps two claims out of each token onto a FHIR resource: the caller's entity type (Patient, Practitioner, RelatedPerson or Device) and entity id (that resource's logical id). Everything downstream, from access rules to the Me query, operates on that pair.

The default provider​

Every project comes with its own identity provider, medbackend-oauth. It needs no configuration: each project has a patient flow and a practitioner flow, managed from the dashboard, and the tokens they issue carry the claims the platform reads.

Endpoints are namespaced by project and entity type:

https://auth.medbackend.com/oauth/{project_uid}/{entity_type}/authorize
https://auth.medbackend.com/oauth/{project_uid}/{entity_type}/token
https://auth.medbackend.com/oauth/{project_uid}/{entity_type}/signup

A token it issues carries:

{
"sub": "<oauth user id>",
"iss": "https://auth.medbackend.com",
"project_uid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"entity_type": "Practitioner",
"entity_id": "def456",
"email": "practitioner@example.com",
"iat": 1718900000,
"exp": 1718903600
}

Tokens are signed RS256 and expire after one hour. Signing keys are published at the provider's OpenID configuration document and rotate without any change on your side.

What a flow offers its users is configured per flow: Sign in with Google, PKCE and public clients, and the flow name users see on sign-in and e-mails.

What the platform reads from a token​

Three claims decide what a caller is: the FHIR entity type, the FHIR entity id, and project_uid.

  • The entity type is one of Patient, Practitioner, RelatedPerson or Device, because it is matched directly against the client_role of your access rules. A token whose entity type matches no rule is authenticated but authorised for nothing, and every request is denied.
  • The entity id is the logical id of a resource that already exists in the project's FHIR store. It is not created on demand.
  • project_uid must name the project in the X-Project-ID header. This pair is the tenant boundary; see the project binding.

Users who already have an account elsewhere sign in through an upstream provider connected to the project's flow, and still receive a token from the project's own provider with these claims. See Sign in with Google.

Troubleshooting​

SymptomLikely causeFix
Authenticated but everything is deniedentity_type is not a FHIR resource type, or no rule matches itCheck the resolved identity with Me, then check your rules
Me returns nullThe token is missing one or both identity claimsCheck which flow issued the token and that its user has a FHIR identity
400 MISSING_PROJECT_UIDX-Project-ID header absentSee the project binding

Security notes​

  • Never commit a client secret or API key to a configuration file. Inject them from a secret manager.
  • The issuer is not the tenant boundary. Two relying parties of the same identity provider share an issuer, so the issuer check cannot separate them. The boundary is the project binding described in Making authenticated requests.
  • The identity claims are set by the provider, never from user input. An entity_id a caller could influence would be a privilege-escalation path.