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 value | Where it goes in Entra |
|---|---|
Service provider entity ID: https://auth.example.com/realms/acme | Identifier (Entity ID) |
Broker endpoint: https://auth.example.com/realms/acme/broker/entra-id-saml/endpoint | Reply 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
- In the Microsoft Entra admin center, go to Entra ID → Enterprise apps → All applications and choose New application.
- 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
- Under Manage, open Single sign-on and choose SAML.
- In Basic SAML Configuration, choose Edit and set:
| Field | Value |
|---|---|
| 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 URL | Leave empty |
- 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 name | Holds |
|---|---|
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name | User principal name |
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress | Email address |
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname | First name |
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname | Last 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
- In the SAML Certificates section, copy the App Federation Metadata Url.
- 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
- Open Identity providers and choose SAML v2.0 (from the list, or under Add provider).
- Fill in the form and choose Add:
| Setting | Value |
|---|---|
| Alias | entra-id-saml |
| Display name | Microsoft |
| Service provider entity ID | https://auth.example.com/realms/acme (the default) |
| Use entity descriptor | On |
| SAML entity descriptor | The App Federation Metadata Url from Entra |
Check the SAML settings
On the provider's Settings tab, check these values and choose Save:
| Setting | Value |
|---|---|
| Identity provider entity ID | https://sts.windows.net/<tenant-id>/ (imported) |
| Single Sign-On service URL | https://login.microsoftonline.com/<tenant-id>/saml2 (imported) |
| NameID policy format | Persistent (the default). Entra then sends a stable pairwise identifier as the NameID. |
| Principal type | Subject NameID |
| HTTP-POST binding for AuthnRequest | Off. Keycloak sends the request by redirect, the binding Entra documents. |
| Want AuthnRequests signed | Off. Entra accepts unsigned requests unless you turn on its own option to require them. |
| Want Assertions signed | On. Entra signs the assertion. |
| Validate Signatures | On |
| Metadata descriptor URL | The App Federation Metadata Url |
| Use metadata descriptor URL | On, so Keycloak picks up Entra's new signing certificate by itself |
| Pass subject | Off. 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):
| Name | Mapper type | Settings |
|---|---|---|
username | Username Template Importer | Template ${ATTRIBUTE.http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name}, Target LOCAL |
email | Attribute Importer | Attribute Name http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress, User Attribute Name email |
first name | Attribute Importer | Attribute Name http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname, User Attribute Name firstName |
last name | Attribute Importer | Attribute 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:
| Field | Value |
|---|---|
| Name | entra-admins |
| Sync mode override | Inherit |
| Mapper type | Advanced Attribute to Group |
| Attributes | Key http://schemas.microsoft.com/ws/2008/06/identity/claims/groups, value the Entra group's Object ID |
| Regex Attribute Values | Off |
| Group | admins (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
- In Entra, check that your test user is assigned to the app.
- In a private browser window, open
https://auth.example.com/realms/acme/accountand choose Microsoft. - Sign in with Entra. You come back to the account console, signed in.
- 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
| Error | Cause | Fix |
|---|---|---|
AADSTS700016: application with identifier https://auth.example.com/realms/acme was not found | The 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 provider | Keycloak 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 requester | The 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 console | The 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 nothing | No 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
- Keycloak Server Administration Guide: SAML v2.0 identity providers, mappers and first login flow
- Keycloak source 26.8.1: SAML UsernameTemplateMapper and AdvancedAttributeToGroupMapper
- Microsoft: Enable single sign-on for an enterprise application with a relying party security token service
- Microsoft: Enable SAML single sign-on for an enterprise application
- Microsoft: Single sign-on SAML protocol
- Microsoft: Customize SAML token claims
- Microsoft: SAML 2.0 token claims reference
- Microsoft: Configure group claims for applications
Connect Microsoft Entra ID to Keycloak (OIDC)
Let users sign in to your Keycloak realm with their Microsoft Entra ID work account over OpenID Connect, and map Entra groups to Keycloak groups.
Connect Google Workspace to Keycloak
Let your Google Workspace users sign in to your Keycloak realm, limited to your own domain, and learn how to bring Google groups along.