RealmDeployDocs
GuidesIdentity providers

Connect Microsoft Entra ID to Keycloak (SAML)

Broker Microsoft Entra ID logins into your Keycloak realm over SAML 2.0 with a non-gallery enterprise app, signed assertions and Entra groups mapped to Keycloak groups.

Users choose Microsoft on your Keycloak login page, sign in with Entra ID, and Entra posts a signed SAML assertion back to Keycloak. Keycloak is the service provider towards Entra and keeps issuing its own tokens to your apps. If you have the choice, OpenID Connect is simpler to set up; use SAML when your organization's policy asks for it.

Checked against the Microsoft Entra ID docs and Keycloak 26.8 on 25 November 2026.

Replace auth.example.com with your RealmDeploy hostname and acme with your realm. <tenant-id> is your Entra Directory (tenant) ID. The guide uses entra-id-saml as the identity provider alias.

Keycloak valueWhere it goes in Entra
Service provider entity ID: https://auth.example.com/realms/acmeIdentifier (Entity ID)
Broker endpoint: https://auth.example.com/realms/acme/broker/entra-id-saml/endpointReply URL (Assertion Consumer Service URL)

The SAML login itself runs through the browser, but Keycloak downloads Entra's federation metadata and signing certificates from login.microsoftonline.com (port 443): once when you import it by URL, and again whenever it refreshes the certificates. Outgoing connections from your tenant are closed by default, so tell us that host through How to reach us before you set it up, and we open it. If you prefer no outgoing connection, import the metadata as a file instead (see the FAQ); then you update Entra's certificate in Keycloak by hand when it changes.

In Microsoft Entra ID

Create the enterprise app

  1. In the Microsoft Entra admin center, go to Entra ID → Enterprise apps → All applications and choose New application.
  2. Choose Create your own application, enter a name such as Keycloak acme, select Integrate any other application you don't find in the gallery (Non-gallery) and choose Create.

Basic SAML Configuration

  1. Under Manage, open Single sign-on and choose SAML.
  2. In Basic SAML Configuration, choose Edit and set:
FieldValue
Identifier (Entity ID)https://auth.example.com/realms/acme (choose Add identifier)
Reply URL (Assertion Consumer Service URL)https://auth.example.com/realms/acme/broker/entra-id-saml/endpoint (choose Add reply URL)
Sign on URLLeave empty
  1. Choose Save.

The identifier must be unique among the apps in your Entra tenant. Entra finds the app by the identifier that Keycloak sends as the request's issuer.

Attributes & Claims

Open Attributes & Claims → Edit. By default Entra sends the user's name (the UPN), email address, first name and last name as claims, and the user principal name as Unique User Identifier (Name ID). Keep the defaults and note the claim names shown, for example:

Claim nameHolds
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameUser principal name
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddressEmail address
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givennameFirst name
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surnameLast name

Then choose Add a group claim, pick Groups assigned to the application (recommended) or Security groups, leave Source attribute on Group ID, and save. Entra sends the groups as object IDs in the claim http://schemas.microsoft.com/ws/2008/06/identity/claims/groups. It leaves the claim out when a user is in more than 150 groups, which is why assigning only the groups you need is safer.

Copy the metadata URL and assign users

  1. In the SAML Certificates section, copy the App Federation Metadata Url.
  2. Under Manage, open Users and groups, choose Add user/group and assign the users or groups who may sign in. With Assignment required? set to Yes under Properties, nobody else can.

In Keycloak

Add the identity provider

  1. Open Identity providers and choose SAML v2.0 (from the list, or under Add provider).
  2. Fill in the form and choose Add:
SettingValue
Aliasentra-id-saml
Display nameMicrosoft
Service provider entity IDhttps://auth.example.com/realms/acme (the default)
Use entity descriptorOn
SAML entity descriptorThe App Federation Metadata Url from Entra

Check the SAML settings

On the provider's Settings tab, check these values and choose Save:

SettingValue
Identity provider entity IDhttps://sts.windows.net/<tenant-id>/ (imported)
Single Sign-On service URLhttps://login.microsoftonline.com/<tenant-id>/saml2 (imported)
NameID policy formatPersistent (the default). Entra then sends a stable pairwise identifier as the NameID.
Principal typeSubject NameID
HTTP-POST binding for AuthnRequestOff. Keycloak sends the request by redirect, the binding Entra documents.
Want AuthnRequests signedOff. Entra accepts unsigned requests unless you turn on its own option to require them.
Want Assertions signedOn. Entra signs the assertion.
Validate SignaturesOn
Metadata descriptor URLThe App Federation Metadata Url
Use metadata descriptor URLOn, so Keycloak picks up Entra's new signing certificate by itself
Pass subjectOff. Entra returns an error when the request contains a subject.
Trust Email (under Advanced settings)Off
Sync mode (under Advanced settings)Force, so names, email and groups update at every login

To check what Entra published, paste the metadata into the SAML metadata viewer.

Map the user's details

Without mappers, Keycloak names the user after the opaque NameID. Add these on the provider's Mappers tab (Add mapper):

NameMapper typeSettings
usernameUsername Template ImporterTemplate ${ATTRIBUTE.http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name}, Target LOCAL
emailAttribute ImporterAttribute Name http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress, User Attribute Name email
first nameAttribute ImporterAttribute Name http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname, User Attribute Name firstName
last nameAttribute ImporterAttribute Name http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname, User Attribute Name lastName

The link between the Keycloak user and Entra stays on the NameID, so a later UPN change does not create a second user.

Groups and roles

Map each Entra group with its own mapper on the Mappers tab:

FieldValue
Nameentra-admins
Sync mode overrideInherit
Mapper typeAdvanced Attribute to Group
AttributesKey http://schemas.microsoft.com/ws/2008/06/identity/claims/groups, value the Entra group's Object ID
Regex Attribute ValuesOff
Groupadmins (create it under Groups first)

To grant a role instead, use SAML Attribute to Role with the same Attribute Name, the group's object ID as Attribute Value, and the Role.

With Sync mode Force, the mapping is checked at every login. Your apps see the groups in Keycloak's tokens once their client has a Group Membership mapper (Client scopes → <client-id>-dedicated → Configure a new mapper).

Accounts are linked the same way as with OpenID Connect. Leave Trust Email off: Microsoft warns that the email claim is not guaranteed to be correct. See first login and account linking.

Test it

  1. In Entra, check that your test user is assigned to the app.
  2. In a private browser window, open https://auth.example.com/realms/acme/account and choose Microsoft.
  3. Sign in with Entra. You come back to the account console, signed in.
  4. In the admin console, open Users, find the user and check the username, email, the Identity provider links tab and the Groups tab.

To see exactly what Entra sent, capture the SAMLResponse form field in your browser's developer tools and paste it into the SAML response decoder.

Common errors

ErrorCauseFix
AADSTS700016: application with identifier https://auth.example.com/realms/acme was not foundThe Identifier (Entity ID) in Entra differs from Keycloak's Service provider entity ID.Make both exactly the same, including https and no trailing slash.
AADSTS50011 (reply URL does not match)The Reply URL in Entra is not the broker endpoint of this alias.Use https://auth.example.com/realms/acme/broker/entra-id-saml/endpoint.
AADSTS50105 (user not assigned)Assignment required? is Yes and the user is not assigned.Assign the user or a group under Users and groups.
Keycloak shows Invalid signature in response from identity providerKeycloak has an old Entra certificate, or the assertion is not signed.Choose Reload keys on the provider; keep Entra signing the assertion.
Keycloak shows Invalid requesterThe response's issuer is not the Identity provider entity ID, or the response does not belong to Keycloak's request.Re-import the metadata so the entity ID is https://sts.windows.net/<tenant-id>/. Start the login from Keycloak, not from the Entra My Apps page.
Import of the metadata URL fails in the admin consoleThe outgoing connection to login.microsoftonline.com is not open yet.Tell us the host through How to reach us, or import the file.
Group mapper adds nothingNo group claim, more than 150 groups, or the attribute name in the mapper differs.Check the claim in the decoded response and copy its name exactly.

FAQ

Can I set this up without any outgoing connection?

Yes. In Entra, choose Download next to Federation Metadata XML. In Keycloak, turn Use entity descriptor off and use Import config from file with that file, and leave Use metadata descriptor URL off. Keycloak then validates signatures with the certificate stored in Validating X509 certificates. When Entra's signing certificate changes, download the new metadata and update that field, or logins fail.

Should the users start from the Entra My Apps page?

Start from your app or from Keycloak. This guide sets up logins that Keycloak starts; Keycloak checks that each response answers one of its own requests.

Can I give Entra Keycloak's metadata instead of typing the URLs?

Yes. Keycloak publishes its service provider metadata for this provider at https://auth.example.com/realms/acme/broker/entra-id-saml/endpoint/descriptor (save the provider first). Download it and use Upload metadata file on Entra's SAML page.

Sources

On this page