When Medplum OAuth2 sign-in fits your healthcare app
If your team is building a patient or practitioner app on Medplum's FHIR API and needs its own sign-in, Medplum Auth can issue tokens through the OAuth2 authorization code flow, so your app never has to collect or store user passwords itself. This fits when you want patients and staff to authenticate against the same user store that governs their access to FHIR data, and when you want the login experience to be consistent across apps built on the same project. The main alternative is embedding a login form inside your own application, which gives you more control over the screens but places credential handling inside your codebase and your security review scope.
Medplum Auth covers OAuth, OpenID Connect and SMART-on-FHIR, which together describe how a client requests authorization, how it receives identity claims and how it gets scoped access to clinical resources. In practice, that means your app redirects users to Medplum's login, receives an authorization code, and exchanges it for tokens that carry the user's FHIR context. Confirm in the Medplum authentication docs which grant types and token behaviors your Medplum version supports before you commit to a design.
Teams usually need an external identity provider instead when staff already sign in through a corporate directory, when they must enforce that organization's MFA and conditional access rules, or when several systems outside Medplum need one identity source. In that case, Medplum can still federate to the external provider, but the decision is about where authoritative user identity lives. Settle that question with your identity team before creating any ClientApplication, because it determines who controls account lifecycle, deprovisioning and audit evidence.
Medplum OAuth2 client options for patient and practitioner apps
This table compares the ClientApplication settings that shape how your app signs in patients and practitioners, and how each choice affects later changes. Read the rows in order, since redirect URIs, the access policy and the sign-in method decide most of the access model. Treat the hard-to-change rows as design decisions to settle before the first production login.
| Setting | What to decide | Trade-off | Hard to change later? |
|---|---|---|---|
| Redirect URIs (web) | Exact callback URLs for each production hostname of your web app | Each hostname and path must match exactly, so every new domain or route needs an added entry | Yes, changes affect every live sign-in |
| Redirect URIs (mobile) | Custom scheme or app link callbacks for iOS and Android builds | Each bundle or scheme change requires a new client entry and an app release | Yes, tied to app identifiers |
| Redirect URIs (development) | Separate localhost callbacks on a non-production ClientApplication | Keeps test sign-ins away from production data, but adds a second client to maintain | No, can be adjusted per environment |
| Access policy | The AccessPolicy assigned to the client that limits what signed-in users can read and write | A broad policy eases development but widens exposure; a narrow one needs more upfront modeling | Partly, policy edits apply without a new client, but scope decisions are costly to unwind |
| Patient users | Whether patients have their own login and which compartment or resources they can reach | Patient scoping through policy and compartments must be tested with real record relationships | Partly, depends on how the data model links patients to records |
| Practitioner users | Whether staff sign in with Medplum-managed accounts and which roles or memberships apply | Role separation adds setup work but supports clearer audit trails | No, memberships can be adjusted per user |
| Hosted login | Use Medplum's own sign-in page through the authorization code flow | Fastest to run and keeps credentials off your pages, with less control over branding | Moderate, switching later changes the sign-in path users see |
| External identity provider | Attach an external provider such as a corporate or consumer identity service to the client | Reuses existing accounts and MFA, but adds provider configuration, user matching and a dependency on the provider | Yes, changing provider or matching rules can strand or duplicate accounts |
Why exact redirect URIs matter for Medplum OAuth2 clients
An exact redirect URI match is the control that keeps an authorization code from being delivered to an address you did not register. In the authorization code flow, the authorization server sends the user's browser back to the redirect URI with a one-time code, and the client exchanges that code for tokens. If an attacker can steer the browser to a different address, they can capture the code and try to use it. For a ClientApplication in Medplum, the redirect URI list on the client is the set of addresses Medplum will accept as a return point, so each entry should be the full callback address your app actually serves, with nothing left to interpretation. Before going live, confirm in the Medplum authentication docs how Medplum compares URIs, including scheme, host, port and path, and whether trailing slashes or query strings are treated as distinct.
Wildcards and loosely managed lists widen that risk. A pattern such as a whole domain or a path prefix lets any page matching the pattern receive codes, including pages added later by someone else, and an open redirect on a registered host can turn a trusted callback into a relay. Lists also accumulate over time: old staging hosts, personal test URLs and retired paths stay enrolled long after anyone remembers them. Treat each redirect URI as a permission. Review the list whenever a route changes, and ask your team to justify every entry during the change record rather than assuming the list is harmless.
Separate ClientApplications for development, staging and production keep these permissions from leaking between environments. A shared client lets a loosely secured development callback receive production authorization codes, and it also makes it hard to rotate or revoke one environment without disrupting the others. With one client per environment, each carries only its own callbacks, its own access policy and its own token settings. Illustratively, a production client might list only the production callback host on your app's main domain, while the development client lists a local address used by engineers. Confirm with your security team that development clients cannot reach production data through the access policy they are assigned.
Set up a Medplum OAuth2 client and fetch tokens
This sequence takes an app from a ClientApplication record in a Medplum project to a working authorization code sign-in, where patients and practitioners reach only the FHIR resources their access policy allows.
Create the ClientApplication in the project
An administrator of the Medplum project creates a ClientApplication for your app, either in the Medplum app or through the API, and records the client ID it generates. Keep the project separate for each environment, such as development, staging and production, so that test data and client settings do not leak between them. The step is done when the client appears in the project with a client ID your team can reference in configuration. Confirm the exact field names and screens in the Medplum auth docs before you start, because they change between releases.
Register exact redirect URIs for each environment
Add the callback URL of each environment to the ClientApplication's redirect URI list, one entry per URL, using the exact scheme, host, port and path your app will send. Do not register wildcards or a shared URL for every environment, because a loose match lets an authorization code return to a page you did not intend. Check the result by starting a sign-in from each environment and confirming that Medplum accepts the redirect. A mismatched URI should fail at the authorization step, and that failure is the expected result for any URL you did not register.
Assign an access policy to the client
Attach an access policy to the ClientApplication so that the tokens it issues can read and write only the resource types your app needs. Start from the smallest set of resource types and operations, then widen it only when a specific screen requires more. Your security team should review the policy as a written artifact, since it defines what a compromised client token could reach. The check is a test patient and a test practitioner each signing in and attempting to read a resource outside their permitted set, which should return an authorization error.
Implement the authorization request
Build the sign-in step in your app so it sends the user to Medplum's authorization endpoint with the client ID, the registered redirect URI, the requested scopes and a state value. For public clients, include a PKCE code challenge and verify the state on return to prevent request forgery. Test the flow with one test patient and one test practitioner, and confirm that each user lands back in your app with an authorization code and the state value you sent. Use the Medplum auth docs for the exact parameters and the login screens users will see.
Exchange the code at the token endpoint
Your backend or client posts the authorization code, redirect URI and, where used, the PKCE verifier to Medplum's token endpoint, and receives an access token and, if granted, a refresh token. Store tokens according to your app's risk model, and do not place client secrets in browser code. The check is a successful token response for each test user, with the access token decoded to confirm the subject and client match what you expect. Token lifetimes are set separately, so confirm the defaults for your client before testing expiry behavior.
Call the FHIR API with the access token
Send requests to the FHIR R4 API with the access token in the Authorization header, starting with a read of the signed-in user's own resource and a search on a resource type the policy allows. Confirm that the test patient sees only their own records and that the test practitioner sees only the resources in their permitted set. Also confirm that a request for a forbidden resource type is refused. When all three checks pass for both test users in every environment, the client is ready for a pilot with real users under your compliance review.
Security controls to set before a Medplum OAuth2 client goes live
A Medplum ClientApplication decides who can sign in, where they land after sign-in, what they can read and how long their tokens last. The controls below cover the points where a loose setting becomes an exposed patient or practitioner record, and each one is something to check before production traffic arrives.
Exact redirect URI matching
Register only the full callback URLs your app uses, with scheme, host, port and path, and no wildcards or open paths. A loose redirect list lets an attacker receive an authorization code meant for your app. Before launch, compare the registered list against the routes in your build and remove anything unused, including old staging hosts.
Medplum auth docsLeast-privilege access policy
Assign each ClientApplication an access policy that grants only the resource types and compartments the app needs. A client built for patient check-in should not inherit broad practitioner rights. Review the policy with the product owner and confirm, in a test project, that a patient-facing login cannot read another patient's records.
Token storage in the client
Decide where access and refresh tokens live before the app is built. Browser code that stores tokens in readable storage exposes them to any script that runs on the page. Confirm the chosen storage approach with your security team, keep refresh tokens off the front end where your architecture allows, and test logout clears them.
MFA for practitioner logins
MFA in Medplum applies to password logins, so practitioners who sign in with a Medplum password need a second factor enabled. Practitioners who sign in through an external identity provider get MFA from that provider's policy instead. Confirm which path each practitioner uses, and check that the enforced method matches your access rules.
Audit trail for client changes
Changes to a ClientApplication, including redirect URIs, policies and token settings, alter who can authenticate. Record who made each change and when, and require a review before a redirect or policy edit reaches production. Ask your Medplum administrator where those change records are kept and how long your retention rules keep them.
Separate clients per environment
Create distinct ClientApplications for development, staging and production, each with its own redirect URIs and policy. A shared client lets a test deployment issue tokens that production trusts, and a leaked development secret then reaches live data. Name each client by environment so reviewers can see which one a request uses.
How patient and practitioner sign-in paths differ
Patients usually sign in to an app that your organization builds, so the identity question is whether the person at the keyboard is the patient named in the record. Medplum models a patient login as a user tied to a Patient resource through a project membership, and the access policy attached to that membership decides what the patient can read and write. Decide before build how a new patient account is linked to an existing Patient record, how identity is verified at registration, and how consent is recorded and checked before data is shown.
- Identity matching: Confirm whether patients self-register or are invited, and which attributes (such as email, date of birth or an external identifier) must match before a link is created.
- Access policy scope: Limit the patient policy to the patient's own compartment so that one patient cannot list or read another patient's resources through search.
- Consent: Decide which consent resources gate which data, and test that revoking consent removes access on the next token use.
- Account recovery: Define how a patient regains access without staff resetting passwords on request, since that path is a common route for account takeover.
- Session length: Set token lifetimes for mobile and shared-device use, which are usually shorter than for staff workstations.
Test with a patient who has no link, a patient linked to a different record, and a revoked consent, and confirm each attempt is refused and logged. Confirm the exact matching rules and SMART scopes with the Medplum authentication documentation before you write them into the policy.
Practitioner apps authenticate clinicians, administrators and other staff who work inside your organization's directory. The main decisions are which identity provider is the source of truth, whether multi-factor authentication is enforced for every sign-in, and how administrators oversee who holds which role. Medplum supports its own login, external identity providers and multi-factor authentication, so the choice of who authenticates the staff member should be made explicitly rather than inherited from a default.
- Identity source: Decide whether staff sign in with a corporate identity provider or Medplum's own login, and confirm how deprovisioning removes access when someone leaves.
- MFA enforcement: Confirm which factor applies to password logins and which factor applies when the identity provider performs the check, so you know where the control really sits.
- Role assignment: Map clinical and administrative roles to access policies and review who can change those policies.
- Administrative oversight: Restrict project admin rights to a small named group and log every change to clients, policies and memberships.
- Shared workstations: Set short session lengths and confirm that sign-out clears tokens in the browser.
Test a deprovisioned user, a user without MFA enrolled, and a clinician attempting an action outside their role. Verify that each attempt is refused and that administrator changes appear in the audit trail. Check the current MFA behavior with the Medplum authentication documentation before you rely on it.
Some apps serve patients and practitioners from the same sign-in page, such as a care team portal where clinicians and patients both log in, or a scheduling app used by staff on behalf of patients. The risk in mixed apps is role confusion: a user who is both a patient and a staff member, or a staff member who views a patient's record through the patient interface, can end up with the wrong permissions. Treat the two audiences as separate client applications or separate policies, and decide how the app routes each user after sign-in.
- Separate clients: Consider one ClientApplication per audience so that redirect URIs, token lifetimes and access policies can differ.
- Dual-role users: Decide whether a person who is both a patient and a clinician gets two identities, and how the app chooses which one to use.
- Routing after login: Confirm the app sends each user to the correct interface and cannot be steered to another audience's screens.
- Shared components: Check that patient-only pages do not reuse staff queries that return broader data.
- Audit separation: Make sure logs show which audience and which client made each request.
Test the same record from both interfaces, a dual-role account, and a patient attempting a staff-only route. Confirm that each path returns only the data its policy allows. Review the access model with your security team before launch, since mixed apps are where scope mistakes most often appear.
Limits to confirm in your environment before you build
Several details decide whether a Medplum OAuth2 login works the way your app needs, and some depend on your plan or hosting model rather than on the code. Confirm these items with Medplum or your own platform team before you write the client, so the design does not have to be reworked later.
Login options included in your plan
Confirm which sign-in methods your Medplum plan includes before you promise patients or staff a login option. Medplum's pricing page lists multiple external identity providers for SSO, such as Okta, Azure and Auth0, as an enterprise feature. Ask whether your plan covers the external providers you plan to use, and whether any of them must be configured at the domain level rather than per client.
Medplum pricingToken lifetime defaults and overrides
Ask Medplum for the current default access and refresh token lifetimes, and whether they can be overridden per ClientApplication. Patient-facing apps and clinician tools often need different idle timeouts, so a single default may not fit both. Confirm how refresh tokens are issued, how long they last, and what happens to open sessions when a user logs out.
Medplum auth docsMedplum Cloud or self-hosted deployment
Confirm whether your environment runs on Medplum Cloud or on a self-hosted server, because the operator of the authorization server changes who manages redirect URI registration, token settings, certificates and login-page behavior. On a self-hosted deployment, your team owns the base URL, TLS termination and the configuration that the client depends on. Document which party is responsible for each setting.
Self-hosting docsSupported redirect URI formats
Ask Medplum which redirect URI formats the authorization server accepts, including scheme, port, path and any allowances for native or mobile app callbacks. Redirect URIs must match exactly, so a trailing slash, a different host or an unregistered port will fail the code exchange. Get the exact list of values your web, staging and mobile builds will use, and register them before testing.
Client behavior across version upgrades
Ask how ClientApplication settings, token endpoint behavior and login pages change between Medplum releases, and how much notice the team gets. Medplum ships patch versions weekly, and self-hosted servers must move through each minor version in order. Confirm which release your login flow was tested against, and plan a regression test of sign-in, token refresh and logout in each upgrade window.
Upgrade guideAccess policy and ownership of the client
Confirm which access policy the ClientApplication will be assigned and who in your organization is allowed to change it. The policy determines what a signed-in patient or practitioner can read and write, so a broad policy on a client that many users reach creates exposure. Ask Medplum how policy changes are audited and who approves them on the Medplum side for your project.
Running the OAuth2 client after launch
Treat the ClientApplication and its access policy as production configuration. Every change to the access policy assigned to your client changes what a signed-in patient or practitioner can read and write, so route those edits through the same review you use for code. Keep a record of who changed the policy, when, and why, and re-run your sign-in and resource tests after each change. Rotate or retire clients on a schedule you write down: when a client is no longer used, remove it, and when a redirect URI is no longer needed, delete it rather than leaving it in place. Confirm in your own environment how Medplum surfaces client changes in its audit trail and how long you keep those logs for your compliance obligations.
Watch failed sign-ins as a security signal, not only a support queue. Repeated authorization failures, token exchange errors, or redirect mismatches can point to a misconfigured release, a stale redirect URI after a domain change, or an attempted abuse of your login flow. Decide in advance who receives these alerts, what volume triggers investigation, and how you separate user error from attack. Confirm which sign-in events your Medplum deployment logs and where they can be exported to your monitoring stack.
Plan every Medplum version change as a sign-in regression test. Medplum targets security patches within 7 days for critical vulnerabilities (CVSS 9.0 or higher) and within 14 days for high ones (CVSS 7.0 to 8.9), so your team needs a standing procedure that can move quickly. On a self-hosted server, you must also upgrade through each minor version in sequence, because skipping versions causes startup failures. Each step is therefore a point where authorization code flow, redirect handling and token issuance should be retested in a non-production environment before production. Use the Medplum upgrading guide to plan the sequence, and budget time for the upgrade path itself, since data migrations can run for long periods on large datasets.
Questions teams ask before building Medplum OAuth2 sign-in
What drives the cost of setting up Medplum OAuth2 sign-in?
Cost follows the number of client types, the identity provider choices and the number of environments, not a single flat fee. A single-page web app with one patient login flow is a smaller job than a patient app, a practitioner app and a native mobile client that each need their own redirect URIs and access policies. Each identity provider you bring in adds configuration, testing and support work. Each environment (development, staging, production) repeats the setup and the verification. Hosting also matters: Medplum Cloud and a self-hosted Medplum server differ in who operates the infrastructure and who maintains the sign-in configuration over time. Ask any quote to list each client, each provider, each environment and who performs the ongoing upkeep.
How long does Medplum OAuth2 sign-in setup take?
Duration depends on the work involved, not on a fixed number of days. The main steps are creating each ClientApplication, registering exact redirect URIs, assigning an access policy, fetching and validating tokens, and testing sign-in for every user type. Most of the time goes to decisions and testing: agreeing which roles can reach which resources, confirming how patients and practitioners are separated, and checking behavior after logout and token expiry. Teams with a clear access model and test identities in place move faster. Ask any proposal to show the steps, the dependencies on your team and the test cases it covers, rather than a single headline number.
What must our team provide before sign-in work starts?
Four inputs remove most of the delay. First, access to a Medplum project where the work can be done, with an admin account that can create ClientApplication resources. Second, the full list of redirect URIs for each app and environment, copied exactly, including scheme, host, port and path. Third, test identities for each user type, such as a patient, a practitioner and a user who should be denied access. Fourth, a written access policy describing what each client may read and write. Your security team should also confirm which token lifetimes and multi-factor requirements apply, because these shape the sign-in experience.
Can our in-house team build Medplum OAuth2 sign-in without a partner?
Yes, a team with experience in OAuth2 and OpenID Connect and access to a Medplum project can build this internally. The Medplum authentication documentation describes the ClientApplication setup and token flow, and your engineers will need to handle the redirect handling, token storage and error paths in your own app. The harder questions are often governance ones: who approves a new redirect URI, how access policies are reviewed, and how changes are tested before production. Decide whether those responsibilities sit with your team today. If they do not, a partner can help design the controls, but the decision to bring in outside help should follow your own capacity review.
What breaks most often in Medplum OAuth2 sign-in?
The most common failures are mismatched redirect URIs, clients that receive tokens broader than intended, and missing test coverage for denied users. A redirect URI that differs by a trailing slash, port or protocol will fail at sign-in, so list every value exactly and test each environment separately. An access policy that is too broad lets a client read records it does not need, so review the policy against the real use cases. Teams also overlook token expiry and logout behavior, so test what happens when a session ends and when a refresh is attempted. Confirm each item against your own environment and the current Medplum documentation before release.
How is a fixed-scope Medplum sign-in engagement quoted?
DeployOpen quotes from a written scope. Before work starts, the scope, deliverables and timeline are agreed in writing. The scope lists the client applications, identity providers, environments, user types, access policies, test cases and handover material included. Anything outside that list, such as a new identity provider added later or a rework of the access model, is handled as a scope change with its own agreed terms. Ask for the scope document to name who performs each step, what you must provide and what acceptance testing looks like. DeployOpen does not publish a price list, so the quote is the output of that written scope.
Does the sign-in setup need ongoing support after go-live?
Yes, most teams need some ongoing work. Medplum ships patch versions weekly, and major versions are supported for a defined period, so the sign-in configuration should be retested after upgrades. New redirect URIs, new client types and changes to identity providers also require review. Ask whether the work is covered by a one-time engagement or a recurring support arrangement, and what each one includes. DeployOpen offers ongoing support, upgrades and continuous testing as retainers, which can be scoped separately from the initial build.
How DeployOpen scopes and delivers Medplum OAuth2 sign-in
DeployOpen treats Medplum OAuth2 sign-in for patients and practitioners as a scoped piece of work with written acceptance criteria. The engagement covers the ClientApplication setup, exact redirect URIs, access policy assignment and token retrieval, deployed inside the infrastructure you control.
How we scope
- We agree in writing which Medplum clients, patient and practitioner sign-in paths, and redirect URIs the work covers.
- Scope names the access policy each ClientApplication receives, so reviewers can confirm which resources each login can reach.
- Engagements are fixed-scope, with deliverables and timelines agreed before work starts; ongoing support is available as a retainer.
How we build
- We create each ClientApplication with exact redirect URIs for every environment, avoiding wildcard entries in production.
- We assign access policies to each client and test that patient and practitioner logins receive only the data they should see.
- We run the authorization code flow end to end, from login through token retrieval, in staging before anything reaches production.
How we hand over
- You receive configuration records covering client IDs, redirect URIs, policy assignments and environment differences, documented for your team.
- Handover includes a test script your engineers can rerun after changes, along with a written list of open items to confirm with your team.
- We document where secrets are stored and who holds administrative access to the Medplum project.
How we support
- Retainers cover updates to clients, redirect URIs and policies as your app changes, and retesting after each Medplum upgrade.
- Security testing of the sign-in flow can be scoped separately, with findings, fixes and a retest in the written scope.
- Ask any provider to confirm in writing how upgrade windows, change control and incident response will be handled for your deployment.

