Medplum token exchange with Auth0 and other external providers

How teams that already sign users in with Auth0 or another external identity provider can let those users call Medplum without a second login, and what to configure on each side.

On this page

Medplum token exchange with Auth0 when users already signed in

Token exchange in Medplum lets a user who already signed in with an external identity provider, such as Auth0, receive a Medplum access token without completing a second Medplum login. The calling application then uses that token to read and write FHIR data under the same rules that apply to any other Medplum user. Teams reach for this when a healthcare app or internal tool already holds an Auth0 session for its staff or patients, and a separate Medplum sign-in screen would add a second password, a second MFA prompt and a second place to disable access. A separate Medplum login fits applications where users never touch the external provider, and a machine client fits server-to-server work with no person in the loop.

The flow depends on four pieces. First, the Medplum ClientApplication carries identity provider settings that tell Medplum which external provider to trust. Second, Medplum calls the provider's userinfo URL with the user's token to retrieve the identity claims it needs. Third, Medplum matches those claims to an existing Medplum user, either by email address or by the subject identifier the provider issues. Fourth, the application makes the token endpoint call that performs the exchange. Confirm the exact field names, required scopes and step order in the Medplum authentication docs for your version, because setting names and examples there are the reference this page does not reproduce.

Choose the matching key before you build. Email matching is easy to review for staff directories, but it depends on the provider verifying addresses and on those addresses staying stable when people change names or domains. Subject matching ties the link to the provider's stable identifier, which holds up better under those changes but makes the initial mapping harder to check by hand. Whichever you choose, test with an illustrative user who has no Medplum profile yet, one whose email has changed, and one disabled in Auth0, and record what Medplum does in each case. Also confirm that the access policies attached to each user still limit what the exchanged token can reach, because the external sign-in does not decide what data a user may see inside Medplum.

How the external token reaches Medplum

The flow starts when a user signs in to the external identity provider and the app receives an access token from it. The app then calls Medplum's token endpoint with that external token. Medplum calls the provider's userinfo URL to read the user's identity, matches the user to a Medplum profile by email or subject, and returns a Medplum access token. Check that the userinfo URL and the matching field are configured for the provider before testing.

Token exchange moves an external sign-in into a Medplum access token, with the userinfo lookup crossing the trust boundary.

Matching and configuration options and when each fits

This table compares how Medplum can match an external identity to a user (by email or by subject) and where the external provider settings live (per client or at project level). Read each row for when the option fits, what breaks if the upstream identity changes, and what to confirm in the Medplum docs before you configure it.

OptionWhen it fitsWhat breaks if the external identity changesWhat to confirm in the docs
Email matchingUsers keep the same work email across the external provider and Medplum, and the provider verifies email ownership before issuing tokensA changed or reassigned email can attach a token to the wrong Medplum profile or fail to match at allWhich claim Medplum reads for email and whether the provider's email is marked verified
Subject (sub) matchingUsers have a stable identifier at the external provider and you want matching that survives email changesA new tenant, re-created user or changed connection can produce a new subject and leave the user unmatchedThe exact claim name used for the subject and how the stored external ID is set up for existing users
Userinfo URLThe provider returns identity claims only at its userinfo endpoint rather than in the token you receiveA wrong or retired URL causes token exchange to fail even when the external login itself worksThe exact field name on the ClientApplication identity provider settings and the URL format your provider documents
Per-client identity provider settingsOne Medplum app (for example, a single patient portal) trusts one external provider and no other app needs itChanging the provider for one client leaves other clients unaffected, but each client needs its own maintenanceWhich fields are set on the ClientApplication resource and how they are supplied in the API call
Project-level identity provider settingsSeveral clients in one project should accept users from the same external providerA change applies to every client in the project, so a misconfigured provider can affect unrelated appsWhether project-level provider settings exist in your Medplum version and how they interact with per-client settings
Token endpoint callA backend or front end swaps the external token for a Medplum token without a second loginAn expired external token, a changed audience or a mismatched client ID stops the exchangeThe token endpoint parameters, the accepted grant type and the audience value your external provider must issue
Multiple external providersStaff and patients arrive from different identity sources and each needs its own matching ruleOverlapping email domains or shared subjects across providers can match the wrong accountWhether one client can list more than one identity provider and how matching is ordered when several apply
Auth0 tenant configurationYour organization already uses Auth0 as its primary login for other systemsRenaming a connection, rotating an Auth0 application or changing its custom claims changes what Medplum receivesThe Auth0 application type, allowed callback settings and which claims your Auth0 Action or rule adds to the token

Configuring the ClientApplication for token exchange

This sequence lets a user who already signed in with an external identity provider, such as Auth0, call Medplum without a second login. Each step ends with a check you can run before moving on, and the final check confirms the Medplum user and membership that the exchange produced.

  1. Confirm the external provider's tokens and userinfo endpoint

    Ask the owner of the external identity provider tenant to confirm that it issues access tokens for the sign-ins you need and exposes a userinfo endpoint. Sign in with a test user, then call the userinfo endpoint with that user's access token. The response should include the email claim you plan to match on and a subject identifier that stays the same across sign-ins. If either value is missing or unstable, fix it at the provider before you change anything in Medplum. Done when a test call returns both values for the test user.

  2. Create or select the ClientApplication

    A Medplum project administrator creates a ClientApplication in the project that will hold these users, or selects an existing one. A dedicated application for token exchange keeps its settings separate from the redirect and token settings of other apps, which makes later reviews easier. Record the client ID, because the token call in a later step needs it. Done when the application appears in the project with an ID you can reference in the remaining steps.

  3. Set the identity provider settings

    On the ClientApplication, enter the external provider's details in the identity provider settings, using the client identifiers and endpoints from the provider's OpenID Connect discovery document. Copy values exactly, because a single character difference will cause token checks to fail. Field names can change between Medplum releases, so confirm them against the Medplum authentication docs before you save. Done when the save succeeds and the stored values match the discovery document.

  4. Set the userinfo URL

    Enter the provider's userinfo endpoint URL in the ClientApplication settings so Medplum can read the signed-in user's claims when it receives an external token. Use the userinfo URL from the discovery document for the same tenant you tested in the first step, not a URL from a different environment. Keep the value under change control, since a wrong tenant here will match users from the wrong directory. Done when the URL is saved and matches the tenant you tested.

  5. Choose the matching attribute

    Decide whether Medplum matches the external user to an existing Medplum user by email address or by subject identifier. Email is easy to read in audit records, but it depends on the provider verifying addresses and on addresses staying unique and stable. The subject identifier stays fixed for each user at a given provider, but it must be recorded for accounts that already exist in Medplum. Choose one, write down the reason, and apply the same choice in every environment. Done when a test account that already exists in Medplum is matched on the chosen attribute.

  6. Assign the access policy to the client

    Attach an access policy to the ClientApplication so that sessions created through the exchange can read and write only the resource types the callers need. Review the policy with the data owners, because a broad policy here applies to every user who signs in through the provider. Keep the policy narrow at the start and widen it only when a documented workflow requires it. Done when a matched test user can read the allowed resource types and receives a forbidden response for a resource type outside the policy.

  7. Make a test token exchange call

    Send the external access token to the Medplum token endpoint, using the grant type and parameters listed in the Medplum authentication docs, together with the client ID from the second step. Run the call with a valid token from a test user, then run it again with an expired or altered token. Avoid writing full tokens to shared logs. Done when the valid call returns a Medplum access token and the invalid calls are rejected.

  8. Verify the Medplum user and membership

    Using an administrator account, look up the ProfileResource and ProjectMembership that the exchange matched or created for the test user. Confirm that they link to the expected external identity, belong to the correct project, and carry the access policy you assigned. Then run the exchange a second time for the same user and confirm that no duplicate profile or membership appears. Done when there is exactly one ProfileResource and one ProjectMembership for that person, with the expected links.

Security risks in external token exchange

Exchanging an external identity provider token for Medplum access moves trust across a system boundary. Each risk below lands on a setting you control in Medplum, the external provider, or the calling app, so each card names the check to run before go-live.

Wrong audience or issuer accepted

A token issued by your Auth0 tenant for another API can be presented to Medplum if the exchange accepts it without checking who it was meant for. Confirm that the identity provider settings on the ClientApplication point only at the issuer you intend, and that the token's audience and issuer match what Medplum expects. Test with a token minted for a different API and confirm it is refused.

Medplum auth docs

Email claims that change

Matching users by email is only as reliable as the claim behind it. An email address can be reassigned, changed by a user inside the provider, or present without verification on some connections. Before using email matching, confirm the provider marks the address as verified, decide who may change it, and compare against subject matching for accounts where the stable identifier is safer.

Over-broad client access policy

The ClientApplication that receives exchanged logins should be bound to an access policy limited to the resources that integration needs. A broad policy turns any valid external sign-in into wide read or write access across the project. Review the policy attached to the client, remove unused resource types, and test with a user who should be denied.

Token lifetimes in the calling app

The external access token and any Medplum token the calling app stores set how long a stolen credential stays useful. Long-lived refresh tokens kept in browser storage extend that window after a user leaves or a device is lost. Set Medplum token lifetimes by application risk, keep tokens out of local storage where possible, and confirm that logout revokes the session on both sides.

External tokens in logs

Gateways, reverse proxies, application logs and error reports often record Authorization headers and request bodies. A raw external token written to a log is a usable credential for anyone who reads that log. Configure logging to redact the Authorization header and token parameters, and check a sample of logs after a test sign-in for any token strings.

Unreviewed exchange changes

Changes to identity provider settings, userinfo URLs or matching rules alter who gets in without any code change. Keep these settings under the same review as code, record who changed them, and re-run the cross-tenant and wrong-user tests after each change so a configuration drift does not go unnoticed.

Why email matching and subject matching behave differently

Matching an external sign-in to a Medplum user by email and matching it by the provider's subject identifier (the sub claim) answer different questions, and the choice decides how accounts link over their lifetime. Email matching follows the person: if the address on the external token matches an existing Medplum user, that user is reused, which is convenient when accounts were created by hand or when the same person already has a Medplum login. Its weakness is that email is mutable. When a clinician changes a surname or moves to a new domain, the address may no longer match, and a new user can be created beside the old one. Subject matching follows the identity at the provider. The sub value stays stable for a given provider account, so it survives email changes, but it is scoped to that provider. The same person signing in through a different provider, or an Auth0 tenant that is rebuilt, gets a different subject and therefore a different Medplum user.

The difference matters most for patients and practitioners in different ways. A practitioner's record is usually tied to a Practitioner resource, access policies and author history, so a duplicate user can split the audit trail and leave clinical work attributed to an account that no longer signs in. Patient accounts are often created by the patient or by a registration flow, so duplicates tend to appear when a patient signs up again with a different address or identity provider. Before you choose, export the users in your Medplum project, list which ones have more than one linked identity or a shared email, and decide how each population should behave when an address changes. Confirm the exact matching options and the fields Medplum uses for each provider against the current Medplum authentication documentation and test them in a non-production project.

Changing the matching strategy after go-live is the costly part. Users created under one rule can be left orphaned when the rule changes, because their stored identifiers no longer match what the provider now sends, and a second run can create duplicates for people who already signed in. Treat the matching rule as a design decision recorded in your identity design document, with a written plan for merging accounts if a mistake is found. Test the plan with the scenarios your organization actually has: an email change, a provider migration, a user who appears under two providers and a deactivated account returning. If you cannot answer how each scenario resolves, the matching rule is not ready for production.

Limits to confirm in your environment

Token exchange depends on details that vary by provider, plan and Medplum release, so none of them should be assumed. The cards below list the points to verify with Medplum and your external provider before you build the flow.

Supported providers and token types

Confirm which external providers Medplum accepts as the source of a token exchange, and which token types each one issues. Auth0 tenants, Google and Cognito can be configured differently, so the ID token, access token and their audience values may not behave the same across them. Ask Medplum for the exact provider list for your release, and test with the token type your users will actually present.

Medplum auth docs

Userinfo response requirements

The exchange often relies on the external provider's userinfo endpoint to return the claims Medplum needs to match a user. Confirm which claims must be present, such as email, email verification status and subject, and whether your provider omits any of them for some account types. A missing or unverified email can change which Medplum profile is matched, so test with real tenant accounts, not only an admin login.

Carry-over of external MFA

Confirm whether a multi-factor challenge completed at the external provider counts for the Medplum session, or whether Medplum applies its own checks. Medplum's MFA methods apply to password logins, and SSO users receive MFA from their provider. Ask how the external provider reports the authentication method in its tokens, and whether your access policies need a stronger assurance requirement than the provider supplies.

Plan and identity provider limits

Multiple external identity providers for SSO are listed as an enterprise feature on Medplum's pricing page, so confirm that your plan covers each provider you plan to use. The same question applies to self-hosted and Medplum Cloud deployments, since plan terms and feature availability can differ. Get the entitlement in writing before design, because the answer changes whether the exchange is a configuration task or a licensing decision.

Medplum pricing

Behavior across Medplum versions

Token exchange behavior can change between Medplum releases, and self-hosted servers must move through each minor version in sequence. Test the full exchange on the exact version you run, and retest after every upgrade, including patch releases that Medplum ships frequently. Record the version and provider configuration together so a later change can be traced to one of them.

Upgrading guide

Questions teams ask before token exchange

Can a user avoid a second login to Medplum after signing in with an external provider?

Often yes, if the external provider already authenticates the user and Medplum is configured to accept that identity. The team's application signs the user in through the external provider, then exchanges that provider's token at the Medplum token endpoint for a Medplum token, so the user never sees a Medplum sign-in screen. The setup lives in the ClientApplication identity provider settings, which tell Medplum which provider to trust and how to look up the user. Whether this fits depends on how much you trust the external provider's session, how long its tokens last, and whether your users need Medplum-specific MFA or project-level controls that the external login would bypass. Confirm those points with your security team before you commit to this pattern.

What drives the effort of a token exchange setup?

Four factors drive most of the effort. The first is the number of external providers, since each one needs its own trust settings, test cases and monitoring. The second is the matching rule: whether users are linked by email address or by the provider's subject identifier, and how you handle changed emails or duplicate accounts. The third is identity data quality, because missing or inconsistent emails and subjects in the source directory cause most failed logins. The fourth is the hosting model. A self-hosted Medplum server means your team owns the network path, certificates and configuration, while Medplum Cloud plans differ in what the team configures directly. Ask any partner to size each factor against your actual provider list in a written scope.

What access does the team need before the work starts?

The work needs three kinds of access. First, admin access to the external identity provider, so someone can register or review the application, confirm which claims and userinfo data it returns, and check which users are in scope. Second, Medplum project admin rights, so the team can create or edit the ClientApplication, set identity provider settings and assign an access policy to it. Third, test users in both systems, including accounts with matching emails, accounts with no match, and accounts that should be rejected. Without test users across these cases, the team can only confirm the happy path. Agree in writing who holds each access level and who approves changes in production.

Can our own engineers set up token exchange without outside help?

Yes, a team with experience in OAuth 2.0 and OpenID Connect and with admin access to both systems can usually do it in-house. The pieces are standard: a client configuration, a trusted provider entry, a userinfo lookup, and a token endpoint call. The harder parts are the ones that tend to surface late: matching rules for real user data, handling users who exist in one system but not the other, token lifetimes that differ between providers, and proving that a rejected user stays rejected. Your team should also document how an external provider outage or a rotated signing key affects sign-in. If your engineers have not done this before, or your compliance team needs a reviewed design, a short independent review is a reasonable middle path.

How long does a setup review take?

The length depends on the number of providers, how clean the identity data is, and whether the review covers only the design or also the test run. A review of a single provider with clear matching rules is shorter than a review that covers several providers, custom claims and a self-hosted deployment. Ask any partner for a timeline in the written scope, with each phase listed separately: discovery of provider settings, design of matching rules, configuration in a non-production project, test cases, and a go-live check. Timelines that do not name these phases are hard to verify. The team's own calendar for access requests and change approvals often sets the real pace.

What goes wrong most often with email or subject matching?

Email matching fails when the external provider returns an address that differs from the one stored in Medplum, for example after a name change, an alias or a domain migration. Subject matching fails when the provider's subject identifier changes after a tenant move or when a second provider issues a different identifier for the same person. Both failures can create duplicate Medplum profiles or, worse, link a user to the wrong record. Decide the rule before go-live, document who resolves exceptions, and test a changed email and a reused email explicitly. Email matching is simpler to explain to auditors, but it depends on the external provider verifying email ownership. Confirm that assumption with the provider's configuration before relying on it.

When should we bring in a partner for token exchange?

Bring in a partner when the setup spans several external providers, when identity data is inconsistent across systems, when your team lacks recent OAuth and OIDC experience, or when a regulator or internal assessor needs a documented design and test evidence. DeployOpen plans, implements, tests and documents self-hosted platforms in the client's own infrastructure, and prepares evidence for compliance assessments, but it does not issue audit reports or certifications. Most engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts, and DeployOpen does not publish a price list, so a quote follows from that written scope. Medplum's compliance documentation states that compliance is a shared responsibility between Medplum and its customers, so decide early which parts of the sign-in design your team owns.

Operating token exchange after go-live

The first operational task is knowing when token exchange fails. Failed calls to the token endpoint, rejected userinfo lookups and sign-ins that create a second Medplum user instead of matching an existing one all look like ordinary login problems to users, so they are easy to miss. Log the outcome of each exchange, alert on a sustained rise in failures, and review the ClientApplication identity provider settings whenever a failure pattern appears. Confirm with your own team which logs your Medplum deployment exposes and how long they are kept, because retention and access to those logs depend on your hosting setup.

Provider-side changes need a named owner on both sides. When your identity provider rotates signing keys, changes the userinfo URL, renames a claim you match on, or switches the application's client secret, the exchange breaks until the Medplum-side settings match. Treat each of these as a change request that touches the ClientApplication, and rotate client settings in a planned window with a test sign-in before and after. Users who leave the external provider should also lose Medplum access on the same schedule. Because a valid exchange depends on the provider still vouching for the user, deprovisioning in the provider must be followed by deactivating the matching Medplum user, and you should confirm how your team does that in your own environment.

Test token exchange again after every Medplum upgrade. Self-hosted deployments must move through each minor version in sequence, and the upgrade guide warns that skipping versions causes startup failures, so the test plan should cover each step rather than only the final version. Keep a set of test accounts that represent a matched user, an unmatched user and a user removed at the provider, and run exchange calls against a non-production environment before each production step. Record which version was running when each test passed, so that a failure after an upgrade can be traced to a specific change.

How DeployOpen scopes Medplum token exchange work

DeployOpen plans and implements Medplum token exchange as part of a self-hosted deployment in infrastructure you control. The work starts with a written scope that names your external identity provider, the users and applications involved, and how users will be matched to Medplum accounts, so the token exchange path is agreed before any configuration begins.

How we scope

  • Confirm which external identity provider issues the sign-in and whether it is Auth0 or another provider your team already uses.
  • Define which Medplum ClientApplications will accept exchanged tokens and which access policies they must carry.
  • Agree in writing whether users match by email or by subject identifier, and document the account conflicts that could occur.

How we build

  • Configure the ClientApplication identity provider settings, userinfo URL and token endpoint call against your self-hosted Medplum server.
  • Test the exchange with real sign-in flows from a staging tenant, including users who already have Medplum accounts and users who do not.
  • Verify token lifetimes, rejected tokens and failed userinfo lookups, and record the results for your security team to review.

How we hand over

  • Deliver configuration records, a matching rule summary, and a step-by-step runbook for adding or retiring external providers.
  • Document the redirect URIs, client settings and secrets locations so your team can audit the exchange without DeployOpen present.
  • Walk your engineers and identity administrators through the setup and the troubleshooting steps for common matching failures.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers, including retesting after Medplum upgrades.
  • Ask for retention terms, named support contacts and response expectations in the written quote before work begins.
  • Confirm with your identity provider vendor which token and claim behaviors may change, and schedule retests when they do.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.