Medplum On-Behalf-Of for server-side applications

Medplum's On-Behalf-Of feature lets your backend act as a named Medplum user so author tracking and access policies still apply, but it requires a Project Admin client and careful identifier handling.

On this page

Medplum On-Behalf-Of for server-side applications: when your backend is the only caller

When your own backend is the only system calling Medplum, every request arrives with the same ClientApplication identity, so the audit trail can show your service account instead of the clinician or staff member who made the change. Medplum's On-Behalf-Of feature addresses this: a server-side ClientApplication with Project Admin rights can act as a Medplum user by sending an X-Medplum-On-Behalf-Of header. According to the Medplum docs, the header takes either a ProjectMembership ID or a profile ID such as a Patient or Practitioner, so the request is evaluated and recorded as that user. The Medplum On-Behalf-Of docs are the primary reference for the exact header behavior and should be read against your Medplum version.

The choice between On-Behalf-Of and per-user tokens comes down to where the user's identity is established. If each person signs in directly to Medplum, or your app can obtain and refresh a token for each user, per-user tokens keep the identity proof with Medplum and are the simpler model to audit. If users authenticate only to your application, and your backend holds the relationship to Medplum, On-Behalf-Of lets that backend carry the user's identity into each call. The trade-off is that the backend becomes a high-privilege actor: a ClientApplication with Project Admin rights can impersonate any user in the project it can reach, so the header value must come only from a verified session in your system, never from client input.

Before you build, confirm three points with your Medplum administrator and your own security review: which ProjectMembership or profile IDs your backend will resolve from its session, how the ClientApplication's Project Admin rights are scoped and logged, and whether your compliance team accepts a shared service identity acting for named users. Test that access policies still apply to the impersonated user by attempting a read and write the user should be denied. Keep a record of which backend code paths set the header, because that list is what an auditor will ask for.

How a backend request is attributed to a Medplum user

The diagram starts with an end user signing into your application, which is the only place their identity is established. Your backend then calls Medplum as a ClientApplication with Project Admin rights, using its own credentials, and adds the X-Medplum-On-Behalf-Of header naming a ProjectMembership ID or profile ID. Check the trust boundary: Medplum trusts the backend's client credentials, so the backend must be the only path that sets that header and it must map the user correctly before sending.

Backend requests carry the client's credentials and the acting user's identifier.

Choosing between ProjectMembership IDs and profile IDs

This table compares the two identifier types the X-Medplum-On-Behalf-Of header accepts, showing what each identifies, where it comes from in your data and when it fits. Read it before you choose what your backend stores and sends, because the choice determines how author tracking and access policies apply to each call.

AspectProjectMembership IDProfile ID (Patient or Practitioner)
What it identifiesOne user's membership in one Medplum project, including the access policy and role that apply inside that projectThe clinical or user resource itself, such as a Patient or Practitioner record
Where it comes fromReturned when your system looks up or creates the membership in Medplum; your backend must store that ID against the userThe FHIR resource ID of the Patient or Practitioner your system already holds, often from your own clinical or identity records
Scope of acting identityActs as that specific membership, so policy evaluation follows the membership's configuration in the projectActs as the linked profile; confirm how the profile maps to membership roles in your project before relying on it
Best fitStaff or service users who already have a membership in the project and whose membership you controlPatient-facing or clinician-facing flows where your backend already keys users by their FHIR resource ID
Stability to confirmConfirm the membership ID persists across re-invites, role changes and project migrations in your environmentConfirm the profile ID is stable across data loads, merges and cutovers, since a changed ID breaks author tracking
Lookup requirementConfirm how your backend resolves a user to a membership ID and whether that lookup is cached or repeated per requestConfirm how your backend maps its own user identifier to the FHIR resource ID before each call
Project Admin requirementThe calling ClientApplication must hold Project Admin rights for either identifier type; confirm this in your project's client settingsThe same Project Admin requirement applies; a client without admin rights cannot act on behalf of a user with either ID
Audit trail effectConfirm in your test project which identity appears in audit events and resource metadata when this ID is usedConfirm which identity appears in audit events and resource metadata, so you know what your compliance team will see

Setting up On-Behalf-Of on a ClientApplication

This sequence gives your backend a single ClientApplication that acts as named Medplum users, so every write and read carries the right author and falls under the right access policies. Each step ends with a check you can run before moving on.

  1. Confirm the server-side ClientApplication

    Your platform or integration team creates a ClientApplication in the non-production Medplum project, or confirms an existing one that your backend already uses for server-to-server calls. Record its ID, the project it belongs to, and which access policy is attached to it. Check that the client uses a credential your backend already stores securely, and that it is not shared with browser code. The step is done when you can fetch the ClientApplication record and see its project and access policy listed. Rollback: if you reuse an existing client, leave its current settings unchanged until the test project passes all checks.

  2. Grant project admin rights to the client

    A project admin in Medplum adds Project Admin rights to the ClientApplication, since only a server-side ClientApplication with those rights can use On-Behalf-Of. Keep this grant limited to the one backend client and avoid giving admin rights to user-facing applications. Confirm the grant in the project settings and record who approved it. The step is done when a test request from the client that sets the header does not fail on permissions alone. Rollback: remove the Project Admin grant from the client, which stops On-Behalf-Of calls from that client without affecting its other access.

  3. Map each application user to an identity

    Build a table that links each user in your application to the correct identifier in Medplum. Use a ProjectMembership ID when you need the act to reflect a specific staff member's membership and its access policy, and use a profile ID such as a Practitioner or Patient when the act should reflect that resource directly. Store the mapping in your backend, and decide who is allowed to create or change it. The step is done when every user who will trigger a Medplum call has exactly one confirmed identifier, and a reviewer has checked a sample of rows against the Medplum project. Rollback: keep the mapping in a versioned file so a bad mapping can be reverted without changing Medplum.

  4. Send the On-Behalf-Of header from the backend

    Update the backend HTTP client so that each outbound request made for a user includes the X-Medplum-On-Behalf-Of header with the mapped ID. The header must be set only in server code, after your application has authenticated the end user, and must never be taken from a value the browser or caller supplies without checking it against your own session. Add logging of the user, the header value and the request path, with no clinical content. The step is done when a request for one test user returns a result scoped to that user and the log shows the matching header value. Rollback: remove the header from the request builder and redeploy, which returns the backend to calling Medplum as the ClientApplication itself.

  5. Test access and author attribution

    Run a set of test requests in the non-production project covering the cases that matter: a read the mapped user should be allowed, a read the same user should be denied by their access policy, a write that should record the mapped user as author, and a request with an unknown or missing identifier. Compare the results with what the same user would see signing in directly. The step is done when each case returns the expected result and the stored resources show the expected author. Rollback: if any case is wrong, return to the mapping or the access policy, fix it in the test project, and repeat the full set before going further.

  6. Confirm the production change and record the evidence

    Before the same settings reach production, your team reviews the test results, the mapping table and the list of who holds the project admin grant, and records them in your change record. Confirm with Medplum documentation or your Medplum contact that the version you run supports the On-Behalf-Of behavior you tested, because behavior can differ across releases. Apply the change through your normal deployment process. The step is done when the change record shows the test evidence, the approver, and the production deployment time. Rollback: redeploy the previous backend build and remove the Project Admin grant if production behavior differs from the test project.

Security risks of acting on behalf of users

On-Behalf-Of moves identity decisions into your backend, so the security of the feature depends on how that backend is privileged, configured and logged. The risks below are connected: each one turns a single powerful credential into a way to act as someone else or to hide who acted.

Project Admin backend can impersonate anyone

A ClientApplication with Project Admin rights can act as any member of the project by sending the X-Medplum-On-Behalf-Of header. If that backend is compromised, an attacker inherits the ability to read and write records as any user, including users with broad clinical access. Scope the admin right to the smallest set of projects possible, keep the client out of shared admin workflows, and confirm which membership the client can target. Restrict who can call the backend before enabling the header.

On-Behalf-Of docs

Wrong ID attributes actions to the wrong person

The header accepts either a ProjectMembership ID or a profile ID such as a Patient or Practitioner, and the two identify different things. Mapping your application's user to the wrong ID can make one clinician's changes appear under another clinician's name, or grant access that belongs to a different role. Test the mapping with known accounts in a non-production project, and confirm that each application user resolves to exactly one membership. Verify the ID type for every mapping path your code uses.

Client secrets stored for long periods

The ClientApplication authenticates the backend with a secret, and anyone who reads that secret can make the same On-Behalf-Of calls. Secrets copied into configuration files, CI variables or container images tend to outlive the people who set them up. Keep the secret in a managed secret store, limit read access to the service that needs it, and plan rotation with a dated owner. Ask whether your organization can rotate the secret without a code release.

Audit trails show the client, not the user

Medplum records the ClientApplication as the actor for calls made on behalf of a user, so the audit trail alone may not show which person initiated an action. In a clinical review, that gap can make it hard to answer who viewed or changed a record. Have the backend log the end user's identity, the target membership, the requested resource and the request time alongside each call, and store those logs where the compliance team can review them. Confirm how your Medplum audit entries and your application logs will be correlated.

Limits to confirm before you rely on On-Behalf-Of

The admin rights that On-Behalf-Of depends on are set inside a Medplum project, but who controls that project differs by deployment model. On a self-hosted server, your team owns the server configuration, the upgrade schedule and the ClientApplication setup, so you must confirm how the feature behaves in the exact version you run. On Medplum Cloud, the hosting, upgrade timing and some administrative settings sit with Medplum, so you need to confirm which project-level controls your plan exposes to you.

  • Version support: Confirm that the header is supported in the release you plan to run, and whether its behavior changed across the minor versions you will pass through during upgrades.
  • Upgrade path: Self-hosted servers must move through each minor version in sequence, so ask whether On-Behalf-Of behavior changes at any step on that path.
  • Cloud plan features: Ask which admin and client settings are available on your Cloud plan and whether any require a higher tier.
  • Support boundaries: Ask who supports issues with header handling, your side or Medplum's, under each model.

Confirm these points against the version and hosting model you will actually operate, not against general documentation.

Questions teams ask before building On-Behalf-Of

Can our team build On-Behalf-Of ourselves without outside help?

Yes, a capable team can build it in-house, since the mechanism is a header on requests from a ClientApplication with Project Admin rights. The harder part is deciding which Medplum user each backend action should be attributed to, and writing the access policies and logging that make those attributions trustworthy. Your engineers need working knowledge of FHIR resources, Medplum access policies and your own audit requirements. Ask whether your team has someone who can own that design over time, because the code is small and the governance is what persists. The On-Behalf-Of docs are the place to confirm the current header behavior before you start.

What drives the effort for an On-Behalf-Of build?

Effort follows four drivers. ID mapping is first: you must decide whether your backend sends a ProjectMembership ID or a profile ID such as a Patient or Practitioner, and map your own user identifiers to those values reliably. Access policy design is second, because the header makes requests run as that user, so each user type needs a policy that limits what the backend can do on their behalf. Logging is third, since your audit trail must record both the service account and the represented user. Testing is fourth, covering cases such as users without membership, deactivated users and requests that should be denied. Each driver grows with the number of user types and workflows you expose.

Which engineers and admins do we need involved?

You typically need a backend engineer to implement the header and token handling, a Medplum administrator with project admin rights to create the ClientApplication and manage membership IDs, and someone from security or compliance to approve the access policies and audit design. Product owners should confirm which actions a backend may take for each user type. If your team runs a self-hosted deployment, platform or infrastructure staff also need to handle secrets storage and environment configuration. Plan for these roles to be assigned before the build starts, since admin rights over the project are a sensitive capability that should be granted deliberately.

How long does an On-Behalf-Of implementation take?

Duration depends mainly on scope: how many user types the backend represents, how many workflows use the header, and how complete your access policies and audit logging must be. A single narrow workflow with one user type is a much smaller job than a backend that acts for patients, practitioners and staff across many endpoints. Testing and compliance review often take longer than the code itself. Medplum does not publish a duration for this work, so ask your team or a partner to estimate it from a written list of workflows, user types and required evidence. A fixed scope agreed in writing makes the estimate easier to check.

Will a Medplum upgrade change On-Behalf-Of behavior?

You should confirm this against the release notes and docs for your target version rather than assume it stays the same. Self-hosted Medplum must be upgraded through each minor version in sequence, so any change in header handling or permission checks would arrive as part of that path. Build regression tests that call the header for each user type and check both allowed and denied requests, then run them in a staging environment before each upgrade. Keep the access policies and ClientApplication settings in version control so you can compare them across upgrades. The Medplum upgrading guide describes the sequence that applies to self-hosted servers.

What are the main security risks of acting on behalf of users?

The main risk is that a ClientApplication with Project Admin rights can act as any user it can name, so a bug in your backend could expose or change records far beyond what a single user should reach. Mitigate this by mapping only the users your workflows need, restricting the ClientApplication's access policy, storing its credentials in a secrets manager, and logging every represented request. Review who holds project admin rights and rotate credentials on a schedule your security team sets. Ask your security reviewers to test denial paths, since a missing check there is the failure most likely to reach production unnoticed.

Does On-Behalf-Of help with audit and compliance evidence?

It can support audit evidence if you design the logging around it, but the header alone does not produce a compliance record. Your audit trail should show which backend service made each call, which Medplum user it represented, what resource was affected and when. Compliance is a shared responsibility between Medplum and its customers, according to Medplum's compliance documentation, so your team must define and retain the evidence your own assessments require. DeployOpen prepares systems, controls and evidence for compliance assessments, but independent auditors and certification bodies issue any audit reports or attestations.

How DeployOpen scopes and delivers Medplum On-Behalf-Of

DeployOpen approaches On-Behalf-Of as a scoped change to how your backend identifies itself and the users it acts for, not as a one-line header addition. We plan the membership and admin model first, then build, test and document the server-side pattern inside infrastructure you control. Engagements are fixed-scope, with scope and deliverables agreed in writing before work starts.

How we scope

  • Map which backend actions need author attribution and which need the calling application's own identity.
  • Confirm which ClientApplication holds Project Admin rights and who approves that privilege in your project.
  • Decide whether each call sends a ProjectMembership ID or a profile ID, and record the reason for each choice.

How we build

  • Implement the X-Medplum-On-Behalf-Of header in your backend with a single, tested helper rather than scattered calls.
  • Write tests that confirm access policies still limit what the acting user can read and write through the proxy.
  • Restrict which backend routes can set the header so callers cannot choose arbitrary identities.

How we hand over

  • Deliver a written design covering membership versus profile choices, admin scope and the audit trail it produces.
  • Provide runbooks for rotating the client credentials and reviewing which identities the backend has acted for.
  • Walk your engineering and security teams through the code, tests and access policy configuration.

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer after handover.
  • Retest the On-Behalf-Of paths when your Medplum version changes, checking the release notes for auth changes first.
  • Confirm with your compliance team which audit records your deployment must keep for each acting identity.

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.