Matrix SSO with Microsoft Entra ID through Matrix Authentication Service

Connect a self-hosted Matrix homeserver to Microsoft Entra ID through Matrix Authentication Service as an upstream OpenID Connect provider. Learn the app registration, claim mapping and why MAS cannot use SAML.

On this page

Matrix SSO with Microsoft Entra ID through Matrix Authentication Service: what the integration does

If your organization runs or plans a self-hosted Matrix server and must sign staff in with Microsoft Entra ID, the integration works through Matrix Authentication Service (MAS), which accepts Entra ID as an upstream OpenID Connect provider. SAML is not supported in MAS, so an Entra ID tenant configured only for SAML application sign-in will not connect directly. Confirm the protocol your Entra ID application is registered for before you plan the work, because the registration must be an OpenID Connect application.

MAS becomes the source of truth for user accounts and access tokens. It runs on its own domain, such as auth.example.com (illustrative), and handles the login redirect to Entra ID, then issues tokens to Matrix clients. The homeserver, Synapse, does not decide who a user is. It only verifies the tokens that MAS issues. This split changes where account state lives, so your team needs to decide which system owns deprovisioning, session lifetime and password or MFA policy before the first user signs in.

The practical consequence is that Entra ID handles the staff identity and conditional access policy, while MAS maps the returned claims to Matrix user IDs and Synapse enforces the resulting access. Check which claim you will use as the stable subject and which claim, if any, you will use for the localpart of the Matrix user ID, since both affect how accounts are named and whether they can be renamed later. Review the MAS upstream identity provider documentation linked from this section's sources before you finalize claim mapping, because the exact configuration keys depend on the MAS version you deploy.

Prerequisites for Matrix SSO with Entra ID through MAS

Entra ID sign-in through Matrix Authentication Service depends on decisions made before any configuration file changes. The cards below cover the homeserver and MAS plan, software versions, the Entra tenant, the MAS domain and access to the server configuration.

Homeserver and MAS deployment plan

Confirm that the homeserver and MAS will run together before you start. With MAS, the authentication service becomes the source of truth for accounts and access tokens, while the homeserver only verifies tokens. Write down which host runs each service, how they reach the database, and which team owns each one. This plan decides whether the Entra configuration can be tested in a staging environment first.

MAS setup docs

Synapse and MAS versions to confirm

Check the running Synapse release and the MAS release against the upstream projects before you plan the change. Recent Synapse releases carry platform floors: Synapse 1.143.0 and later require PostgreSQL 14 or newer, and 1.142.0 and later require Python 3.10 or newer. Confirm these floors against the release you actually run, and read the upgrade notes for every release between your current version and the target.

Synapse upgrade notes

Entra tenant and app registration rights

Identify the Microsoft Entra tenant that holds the Matrix users and confirm that the person configuring the sign-in can register applications in it. Check whether your organization restricts app registration to administrators or requires approval for redirect URIs and client secrets. Agree who owns the registration after go-live, because the client secret and redirect URI will need rotation and updates over time.

DNS and TLS for the MAS domain

MAS runs on its own domain, such as auth.example.com, so it needs a DNS record and a valid TLS certificate before it can serve sign-in. Plan the public hostname, the certificate source, and the reverse proxy that terminates TLS. Confirm that the redirect URI registered in Entra matches the MAS callback address exactly, since a mismatch is a common cause of failed sign-in.

Access to homeserver configuration

Someone must be able to edit the Synapse configuration and the MAS configuration, restart both services, and read their logs. Confirm which hosts, configuration management tools and secret stores hold the client secret and the MAS encryption secrets. Check whether change control requires a review step for authentication settings, and whether a rollback path exists in case users cannot sign in after the change.

Configuring the Entra ID app registration and MAS upstream provider

This sequence registers Matrix Authentication Service as an application in Microsoft Entra ID, then points MAS at the tenant as an upstream OpenID Connect provider so that Entra ID sign-ins create or match Matrix accounts. The result is a tested sign-in flow that you can review before users rely on it.

  1. Confirm the MAS callback URL pattern

    Before touching Entra ID, the identity or platform engineer reads the upstream identity provider section of the MAS documentation and records the callback (redirect) URL pattern that MAS expects for an upstream provider. The URL is built from the public base address of your MAS instance, such as the auth subdomain on your own domain, and a provider identifier you choose. Write the exact value in your change record, because it must match character for character in the Entra ID registration. Done means you have one written redirect URI per upstream provider, and that it uses HTTPS on the MAS domain.

  2. Register the application in Entra ID

    An administrator with rights to create app registrations opens the Microsoft Entra admin center and registers a new application for the MAS instance. Set the platform to a web application and enter the redirect URI recorded in the previous step. Limit supported account types to your own tenant unless you have a documented reason to widen them. Done means the application appears in the app registrations list with the redirect URI shown under the Web platform.

  3. Create the client secret or certificate

    In the same registration, the administrator creates a client credential for MAS. A client secret is the simpler option, but it has an expiry date that you must track and rotate. A certificate is more work to set up but is often preferred by security teams for long-lived services. Store the value in your secrets manager, not in a configuration file in a repository, and confirm who will receive expiry alerts. Done means the credential exists, its expiry is recorded, and the value is available to the MAS deployment through your secrets process.

  4. Record the tenant issuer and client ID

    From the application overview page, copy the application (client) ID and the directory (tenant) ID. Build the OpenID Connect issuer from your tenant ID in the form Entra ID documents for v2.0 endpoints, then open that issuer's discovery document in a browser or with a request tool. Check that the JSON lists the authorization, token and userinfo endpoints and the supported scopes, including openid, profile and email. Done means the discovery document loads without error and the issuer value in it matches the one you recorded.

  5. Add the upstream provider to MAS configuration

    The MAS administrator adds an upstream OpenID Connect provider entry to the MAS configuration file, using the issuer, client ID, client secret reference and the redirect path confirmed earlier. Decide which claim will supply the localpart of the Matrix ID and whether the email claim should be trusted for matching existing accounts, and write both choices down for review. Keep the configuration under version control with the secret referenced rather than embedded. Done means the configuration validates with the MAS tooling you use and the file diff has been reviewed by a second person.

  6. Restart or reload MAS

    The operator restarts or reloads the MAS service so the new upstream provider takes effect, following the restart method used by your deployment, whether that is a systemd unit, a container or a Helm release. Watch the MAS logs during startup for errors about the provider configuration, the discovery request or the secret. Done means MAS starts cleanly, logs show no provider initialization errors, and the login page lists the Entra ID option.

  7. Test a sign-in and confirm the Matrix ID

    Use a test account in your tenant, not an administrator's everyday account, and sign in to Matrix through the MAS login page using the Entra ID option. Approve the consent prompt if one appears. After the redirect completes, check that the session is established and that the Matrix ID shown in your client matches the claim mapping you designed, for example @user:example.com. Repeat the test with a second account and with a user who already has a Synapse password account if you are migrating. Done means the test accounts reach the Matrix client with the expected identifiers, and any mismatch is recorded as a blocker before rollout.

How Entra ID claims map to Matrix user IDs

The mapping decision comes before the first login, because MAS turns the claims Entra ID returns into the Matrix localpart that becomes part of every user ID (@localpart:example.com). The subject claim (sub) is the stable identifier Entra ID issues for each account and is the safest value to link an upstream identity to a MAS user. The preferred username, email address and display name are human-readable, but they can change when an employee is renamed, marries, or has an alias updated. Using a mutable attribute as the localpart means a later change either creates a second account or leaves the old identifier in every room history. Before you configure anything, confirm in the MAS upstream provider documentation which claims the mapping template can read, the exact claim names for Entra ID, and the template syntax for the localpart and display name fields.

Choose the localpart rule as a written policy and test it with a few real staff accounts in a non-production tenant. Decide what happens with duplicate names, shared mailboxes, guest accounts and service principals, since a rule that works for employees may produce collisions or unwanted accounts for them. Also decide who may sign in at all, because the tenant's user assignment and any group restrictions on the Entra ID application determine that, not the Matrix mapping. Lowercase rules, character limits and reserved names differ between Matrix and Entra ID, so check how the template handles them rather than assuming the output is valid.

Existing Synapse SSO users are the hardest part of the change. Accounts created through Synapse's own oidc_providers or other SSO paths are not automatically linked to the new MAS identity, and a mapping that produces a different localpart will create a second Matrix account with separate rooms and history. Inventory current user IDs, compare them with the planned MAS output, and confirm with the MAS and Synapse migration documentation how existing accounts are linked before you cut over. Keep a record of the mapping decision in your change log, because it is very hard to reverse once users have joined rooms under their identifiers.

Entra ID attributes mapped to Matrix user fields

This table compares each Entra ID attribute a MAS upstream provider can read with the Matrix field it could fill, and notes how stable and unique that value is. Read it before choosing the localpart source, because a Matrix user ID is hard to change once accounts and rooms exist. The main takeaway is to map the immutable subject identifier to a stable internal key and treat human-readable names as display data.

Entra ID attributeSuggested Matrix fieldStability and uniquenessWhat to confirm in the tenant before go-live
Subject identifier (sub)Upstream link key only, not the localpartUnique per application registration and stable over time; the value is the strongest key for linking a returning userConfirm the sub value is issued to your app registration and that it does not change after a user is renamed
Object ID (oid)Internal reference for account lookup, if exposedUnique within the tenant and stable for the life of the user objectConfirm whether your token configuration includes oid and which claims your admin team can see in sign-in logs
User principal name (UPN)Localpart candidate, after policy reviewUnique in the tenant but can change when a user is renamed or a domain is changedAgree the naming convention with HR and identity teams, and confirm how renames and domain moves are handled
preferred_usernameLocalpart candidate, only with a fixed formatUsually matches the sign-in name, so it can change and may not be unique across guest or external identitiesCheck that every account in scope has a value, and whether guest or B2B accounts appear in the sign-in flow
Email (email claim)Matrix email address (threepid) and contact fieldCan be empty, shared, reassigned or changed; not a safe primary keyConfirm the email claim is populated for all users and decide whether unverified addresses are accepted
Name (name, given_name, family_name)Display nameEditable by users and administrators; not unique, so it should never identify an accountConfirm the display name source and whether users may edit it in their Entra profile

Why SAML is not an option in MAS

Matrix Authentication Service accepts OpenID Connect upstream providers only, so the SAML question is really a question about which identity path to build. The cards below separate the supported Entra ID route from the bridge route for SAML-only sources, and flag the Synapse saml2_config setting that does not carry over.

MAS takes OIDC upstreams only

Matrix Authentication Service is an OpenID Connect and OAuth 2.0 provider that sits between your users and the homeserver. Its upstream identity providers must speak OpenID Connect, and MAS does not support SAML as an upstream protocol. A SAML-only Microsoft Entra ID enterprise application, or an ADFS trust, cannot be attached to MAS directly. Confirm the protocol of your Entra configuration before you plan the app registration.

MAS upstream docs

Use an Entra ID OIDC application

The supported route for a Microsoft tenant is to register an OpenID Connect application in Entra ID and configure it as an upstream provider in MAS. This needs a client ID, a client secret or other client authentication method, and a redirect URI that points at MAS. Ask your identity team whether the tenant already has an app registration you can reuse, and whether Conditional Access and group assignment apply to that application.

Place Dex in front for SAML

The projects recommend Dex as a bridge when the source is SAML or LDAP. Dex connects to the SAML identity provider on one side and presents an OpenID Connect interface to MAS on the other. This adds a service you must deploy, patch, back up and monitor, and it adds a second hop where claims can be altered or dropped. Treat Dex as part of your authentication boundary in the security review.

Upstream provider options

Keep Synapse saml2_config separate

Synapse can authenticate users through its own saml2_config setting, which uses pysaml2. That path is configured in homeserver.yaml and does not carry over when you move to MAS. If your current deployment uses it, plan a cutover that moves login to the new upstream provider and confirms that existing accounts still map to the same Matrix user IDs.

Decide the SAML path before the build

Choose between an Entra ID OIDC application and a Dex bridge at the start of the project, because the choice changes the number of services, the claim mapping work and the test plan. Record which source is authoritative for each user and which attributes Matrix needs. Ask your team to confirm whether any SAML-only app in the tenant must stay on SAML for other systems, since that affects whether a separate OIDC app is acceptable.

How a Matrix login flows through Entra ID and MAS

The login starts in the Matrix client, which sends the user to the homeserver and then to Matrix Authentication Service on its own domain. MAS redirects the browser to Microsoft Entra ID as the upstream OpenID Connect provider, and the returned identity is mapped to a Matrix user ID. MAS then issues tokens, and the homeserver only verifies them. Check the trust boundary: Entra ID is an external endpoint, while MAS and the homeserver run in your environment.

Login path from the Matrix client through MAS to Entra ID and back.

Security settings for Entra ID sign-in on MAS

Once Microsoft Entra ID is wired into Matrix Authentication Service as an upstream OpenID Connect provider, MAS becomes the place where Matrix accounts and tokens are issued. The cards below cover the controls that decide who can sign in, how the Entra application credential is kept alive, and who can change the trust relationship. Exact settings belong in the MAS and Entra documentation, so each card points you to what to verify.

Client secret or certificate handling

The Entra app registration gives MAS a client credential for the OpenID Connect exchange. A client secret is simpler to create but has an expiry date that must be tracked, and a certificate or other supported credential type can reduce exposure in configuration files. Store whichever you choose in your secrets manager, not in the MAS config file, and confirm in the MAS upstream provider documentation how the credential is injected at runtime. Record the expiry date and the owner so a lapsed credential does not lock every Matrix user out at once.

MAS upstream docs

Rotation without a sign-in outage

Rotation is where most upstream SSO outages start. Add the new Entra credential while the old one is still valid, roll it into the MAS deployment, confirm a test sign-in, then remove the old credential. Check the Entra portal for both credentials during the overlap window, and confirm with Element or your MAS release notes whether any configuration reload is needed. Schedule rotation before the expiry date, not after the first failed login.

Restricting sign-in to your Entra tenant

Limit the upstream provider to your own Entra tenant, using the tenant-specific issuer rather than a multi-tenant or common endpoint, so accounts from other directories cannot authenticate. In Entra, turn on user assignment required for the enterprise application so only assigned users or groups receive tokens. Test with an account outside the assignment group to confirm it is refused before you go live.

Upstream provider setup

TLS on the MAS domain

MAS runs on its own domain, such as auth.example.com, and it handles credentials, consent screens and token issuance for every Matrix client. Serve it only over TLS with a certificate your clients trust, and confirm that redirect URIs registered in Entra use https. Check that the homeserver's trust of MAS tokens depends on MAS being reached at the URL you configured, and that plain HTTP is not exposed on any path.

Protecting MAS signing keys and database

MAS signs the access tokens the homeserver verifies, and it stores user accounts and session state in its database. Keep signing keys in your secrets management system with restricted read access, and plan how they are rotated and backed up. Restrict database access to the MAS service account, and include the MAS database in your backup and restore tests. Confirm the key and database settings in the MAS setup documentation before you run it in production.

MAS setup docs

Limiting who can change the upstream provider

Changing the upstream provider or its claim mapping changes who gets a Matrix account and which identity maps to which user ID. Limit write access to the MAS configuration and the Entra enterprise application to a small named group, and require review for changes. Log configuration changes through your change process, and review Entra sign-in and audit logs for the app on a schedule your security team sets.

Common Entra ID and MAS sign-in failures

This table lists the sign-in failures teams most often hit when MAS uses Microsoft Entra ID as its upstream OpenID Connect provider. Each row gives the likely cause and the first fix to try, so you can work from the symptom you see to the setting most likely to be wrong.

FailureLikely causeFirst fix to try
Redirect URI mismatch at Entra IDThe redirect URI registered in the Entra app registration does not exactly match the callback URL MAS builds from its public domain, including scheme, host, path and trailing slash.Copy the callback URL from the MAS upstream provider configuration into the app registration's web redirect URIs, then compare character by character.
Wrong issuer or discovery URLThe issuer or discovery endpoint points at the wrong tenant, is a v1 endpoint instead of v2.0, or uses a placeholder tenant ID.Open the tenant's OpenID configuration document in a browser and confirm its issuer value matches the issuer set in the MAS provider entry.
Missing claims in the ID tokenThe subject, email or display name claim is not issued because the app's token configuration or requested scopes do not include it.Check the optional claims and requested scopes on the app registration, then confirm the claim names match the MAS mapping template exactly.
Unexpected or duplicate Matrix IDsThe mapping template builds the localpart from a claim that is not unique, changes between users, or contains characters Matrix does not allow.Pick a stable, unique claim such as a verified user principal name or object ID, and test the template with a single account before enabling the provider for everyone.
Clock or TLS errors on the MAS domainThe server hosting MAS has a skewed clock, or the certificate chain for the MAS domain is incomplete or untrusted by the outbound client.Synchronize time on the MAS host, then test the MAS domain and the Entra discovery URL with a TLS client from that same host.
Tokens rejected by the homeserverSynapse is not configured to trust MAS, the MAS public URL or client secrets do not match between the two services, or the homeserver is pointed at the wrong MAS endpoint.Compare the MAS endpoint and shared configuration in the homeserver against the MAS setup docs, then restart both services and retry a login with a new session.
Sign-in loop or error after consentThe user has not consented to the app, or a conditional access policy blocks the sign-in for that user or client.Review the sign-in logs for the app in Entra ID, then confirm the user is assigned and any conditional access policy allows this application.

Questions buyers ask about Entra ID SSO with MAS

How much effort and time does Entra ID SSO through MAS take?

The effort depends mainly on how much of the setup is new to your team: the Entra app registration, the MAS upstream provider entry, the claim mapping to Matrix user IDs, and the test plan for existing accounts. A tenant with a clean app registration process and an owner who can approve it moves quickly, while a tenant with slow change control, many attribute variations or no staging Matrix environment takes longer. No duration is set in the supplied facts, so ask any partner for a written plan that lists each step, the people it depends on, and the test cases before accepting a timeline. Also ask whether the quote covers only the first environment or staging and production together.

Can our own team set up Entra ID SSO with MAS in-house?

Yes, a team with experience in OpenID Connect, a working MAS deployment and access to the Entra tenant can do this in-house. The work is mostly configuration and verification rather than custom code, but mistakes in the redirect URI, the issuer, the subject claim or the user ID mapping can lock users out or create duplicate accounts. Be honest about the skills available: someone must own the Entra app registration, someone must own MAS and the homeserver, and someone must test sign-in, logout and account recovery. If one of those roles is thin, a partner can take on the gap, scoped in writing.

What do we need from the Entra tenant owner and the Matrix admins?

The Entra side needs an administrator who can register the application, create a client secret or certificate, set redirect URIs and decide which users or groups are assigned to it. The Matrix side needs admins who control the MAS configuration, the homeserver settings, the DNS for the authentication domain and the secrets store. Agree in advance who approves each change, where client credentials are kept, and how the Entra admin will rotate them. Without that agreement, the most common delays are waiting for a tenant change window and discovering that no one holds the MAS secrets.

Do SAML-only Entra tenants need Dex or another bridge for MAS?

MAS does not support SAML, so a tenant that offers only SAML for Matrix needs a bridge in front of MAS. The MAS documentation recommends Dex for SAML or LDAP sources, which means Dex authenticates against the SAML source and presents OpenID Connect to MAS. Check whether your Entra application can be configured for OpenID Connect at all, because for many Microsoft tenants it can, and that path avoids an extra service. If you must bridge, add Dex to your operations scope, including its own upgrades, certificates and monitoring, and review the trade-offs against keeping Synapse's own SAML configuration.

What changes for users who already sign in to Synapse through SSO?

Moving to MAS changes where accounts and tokens are managed, so existing Synapse SSO users need a deliberate migration plan rather than an assumption that they keep their sessions. MAS becomes the source of truth for accounts and access tokens, and the homeserver only verifies tokens. Plan how existing Matrix user IDs will be matched to the identities that Entra returns, test a sample of accounts on staging, and tell users that they may need to sign in again and re-verify devices. Confirm the exact migration steps in the Synapse and MAS upgrade documentation for your versions before the cutover date is set.

Which claims from Entra ID decide the Matrix user ID, and what breaks if they change?

The Matrix localpart is built from a claim you choose in the MAS upstream provider configuration, so the claim must be stable, unique and meaningful for the homeserver. Teams often map a display name or email address, but both can change, and a changed value can produce a new Matrix account while the old one is orphaned. Choose an identifier that Entra keeps stable for the life of the user, document the mapping, and test a renamed user before go-live. Confirm the claim names and available attributes in your own tenant, since they depend on your application configuration.

What does DeployOpen provide for this integration?

DeployOpen plans, implements and documents self-hosted open-source platforms inside your infrastructure, so for this topic the work can cover the Entra application configuration guidance, the MAS upstream provider setup, the claim mapping design, staging tests and the operations notes your team needs. Most engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts, and ongoing support is available as a retainer. DeployOpen does not publish a price list, so ask for a quote built from your written scope, and confirm which parts your own admins will do.

How DeployOpen scopes and delivers Matrix SSO with Entra ID

Matrix SSO with Entra ID through MAS touches app registration, claim mapping, token flows and operator documentation, and each one depends on the others. DeployOpen plans these pieces together in a written scope, then builds and tests them inside your own infrastructure so your identity and security teams can review every step.

Identity and claim planning

Before any configuration, DeployOpen agrees which Entra ID attribute becomes the Matrix localpart, how display names and email addresses are read, and which tenant or group membership is allowed to sign in. Because the claim decides the Matrix user ID, a wrong choice is expensive to change later. The plan records the claim names, the server_name and the expected user ID format for review before build starts.

MAS upstream docs

Upstream provider build

DeployOpen configures the upstream OpenID Connect provider entry in Matrix Authentication Service on your domain, including the client registration in Entra ID, redirect URIs and the claim mapping template. The auth service runs on its own hostname in your environment, and the homeserver is set to trust its tokens. Secrets are stored in your secret management system rather than in configuration files shared with the team.

Sign-in and token testing

Testing covers first sign-in for a new user, return sign-in for a user who already exists, sign-in from a user outside the permitted group, and token refresh and revocation. DeployOpen also checks that the homeserver accepts MAS-issued tokens and that disabling an account in Entra ID stops new sessions. Each test case, its expected result and the observed result are recorded in the handover file.

Infrastructure and access controls

DeployOpen reviews where the MAS service, the reverse proxy and the homeserver run, which networks can reach the admin endpoints, and how outbound calls to Entra ID are allowed through egress rules. It also checks TLS certificates, redirect URI exactness and the access policies you choose in Entra ID, such as conditional access and assignment requirements. Findings are listed with owners so your team can accept or fix them.

Documentation and handover

The handover covers the configuration as deployed, the claim mapping rules, a runbook for rotating the client secret, steps for adding or removing users, and a rollback procedure. Operators learn how to read MAS logs when sign-in fails. DeployOpen does not issue audit reports, so the documentation is written to give your compliance team and any independent assessor the evidence they request.

Written scope and ongoing support

Engagements are fixed-scope, so the identity sources, number of environments, test cases and deliverables are agreed in writing before work starts, and the quote follows from that scope. Support after handover can be arranged as a retainer for upgrades, secret rotation and new upstream changes. Ask for the scope to name any Entra ID tenant configuration that remains with your identity team.

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.