RealmDeployDocs
GuidesIdentity providers

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.

Users choose Microsoft on your Keycloak login page, sign in with their Entra ID work account, and come back to your app with a Keycloak token. Keycloak is the broker: your apps keep talking only to Keycloak and do not change.

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 as the identity provider alias, so the redirect URI is https://auth.example.com/realms/acme/broker/entra-id/endpoint.

Keycloak calls Entra from your tenant: it redeems the login code at Entra's token endpoint and downloads Entra's signing keys (JWKS) to check the ID token. Outgoing connections from your tenant are closed by default. Before you test, tell us the host login.microsoftonline.com on port 443 through How to reach us, and we open it. If you leave Disable user info off (step below), Keycloak also calls graph.microsoft.com, so name that host too.

Which Keycloak provider to use

Keycloak offers two ways to add Entra ID. Use OpenID Connect v1.0.

OpenID Connect v1.0 (this guide)Built-in Microsoft provider
What Keycloak readsThe signed ID token, checked against the issuer https://login.microsoftonline.com/<tenant-id>/v2.0Your profile from Microsoft Graph (/me) with an access token; the ID token is not used
TenantFixed by the discovery URL you enterMulti-tenant common endpoints unless you fill in Tenant ID
Groups claimRead from the ID tokenNot read
Group and role mappersAdvanced Claim to Group and Claim to Role are availableThose two mappers are offered only for OpenID Connect providers

With the tenant-specific discovery URL, Keycloak only accepts ID tokens issued by your tenant, and the Entra groups claim can drive Keycloak groups and roles.

In Microsoft Entra ID

Register the app

  1. In the Microsoft Entra admin center, go to Entra ID → App registrations and choose New registration.
  2. Enter a Name, for example Keycloak acme.
  3. Under Supported account types, choose Single tenant only.
  4. Choose Register. On the Overview page, copy the Application (client) ID and the Directory (tenant) ID.

Add the redirect URI

  1. Under Manage, open Authentication and choose Add Redirect URI.
  2. Choose the Web platform and enter https://auth.example.com/realms/acme/broker/entra-id/endpoint. Choose Configure.
  3. Add a second redirect URI to the same Web platform: https://auth.example.com/realms/acme/broker/entra-id/endpoint/logout_response. Keycloak sends users there after it signs them out of Entra, and Entra only accepts a post-logout address that is registered as a redirect URI.

You do not need the ID tokens (used for implicit and hybrid flows) checkbox. Keycloak uses the authorization code flow.

Create a client secret

  1. Open Certificates & secrets → Client secrets → New client secret.
  2. Enter a description, choose an expiry and choose Add.
  3. Copy the secret's Value right away. Entra shows it only once. The Secret ID is not the secret.

Secrets last at most 24 months. Sign-in through Entra stops working the day the secret expires, so note the date. Microsoft recommends certificates over client secrets for production. This guide uses a secret, the method Keycloak's own Microsoft instructions use.

Add claims to the ID token

Under Manage, open Token configuration:

  1. Choose Add optional claim, pick the ID token type, select email, given_name and family_name, and choose Add.
  2. Choose Add groups claim. Pick Groups assigned to the application (recommended) or Security groups. Leave the ID token value on Group ID and choose Add.

With Groups assigned to the application, only groups you assign to the app appear in the token. Assign them in Entra ID → Enterprise apps, open the app, then Users and groups → Add user/group. Entra drops the groups claim completely when a user is in more than 200 groups, so assigning only the groups you need keeps it working.

In Keycloak

Add the identity provider

  1. Open Identity providers and choose OpenID Connect v1.0 (from the list, or under Add provider if the realm already has one).
  2. Fill in the form and choose Add:
SettingValue
Aliasentra-id
Display nameMicrosoft (the button text on the login page)
Use discovery endpointOn
Discovery endpointhttps://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration
Client authenticationClient secret sent in the request body
Client IDThe Application (client) ID
Client SecretThe secret Value

The Redirect URI shown at the top of the form must match the one you registered in Entra character for character.

Check the imported settings

Keycloak fills the endpoints from the discovery document. On the provider's Settings tab, check these and choose Save:

SettingValue
Issuerhttps://login.microsoftonline.com/<tenant-id>/v2.0
Validate SignaturesOn
Use JWKS URLOn
JWKS URLhttps://login.microsoftonline.com/<tenant-id>/discovery/v2.0/keys
Scopes (under Advanced)openid profile email
Disable user info (under Advanced)On. Keycloak then reads everything from the ID token and does not call graph.microsoft.com.
Backchannel logout (under Advanced)Off. Logout then runs through the browser and needs no extra outgoing connection.
Trust Email (under Advanced settings)Off. See First login and account linking.
Sync mode (under Advanced settings)Force, so names, email and group mappings update at every login

You can open the discovery document in the OIDC discovery viewer to compare the values.

Groups and roles

Each Entra group arrives as its object ID in the groups claim. Map each one with its own mapper:

  1. Create the target group under Groups, for example admins.
  2. Open Identity providers → entra-id → Mappers and choose Add mapper.
  3. Fill it in and choose Save:
FieldValue
Nameentra-admins
Sync mode overrideInherit
Mapper typeAdvanced Claim to Group
ClaimsKey groups, value the Entra group's Object ID
Regex Claim ValuesOff
Groupadmins

To grant a role instead of a group, use Claim to Role with Claim groups, Claim Value the group's object ID, and the Role to grant.

With Sync mode Force, Keycloak re-checks the claim at every login and removes the user from the group when the claim no longer matches. With Import, the mapper only runs at the user's first login.

Your apps see these groups in Keycloak's own tokens once the app's client has a group mapper: on the client, open Client scopes → <client-id>-dedicated → Configure a new mapper → Group Membership.

First login and account linking

The first time someone signs in through Entra, Keycloak runs the First login flow (by default first broker login):

  1. Review Profile shows the user's profile when a required field is missing.
  2. Create User If Unique creates a new Keycloak user and links it to the Entra account, unless a Keycloak user with the same email or username already exists.
  3. If one exists, Keycloak shows Account already exists. The user can choose Add to existing account and must then prove they own that account: by a link sent by email (only when the realm has SMTP set up, which is another outgoing connection) or by signing in with that account's password.

After the first login, Keycloak links the account by Entra's sub claim, which does not change when the user's email or UPN changes.

Trust Email tells Keycloak to treat the email from Entra as verified. Leave it off. Microsoft states that the email claim is not guaranteed to be correct and can change, and should never be used for authorization. Keycloak's own docs call automatic linking of existing accounts a potential security hole. Do not build a first login flow that links accounts by email without asking the user to prove ownership (for example one with Automatically set existing user), unless every account in the realm comes from this one Entra tenant.

Test it

  1. In a private browser window, open https://auth.example.com/realms/acme/account and choose Microsoft.
  2. Sign in with an Entra user. You come back to the account console, signed in.
  3. In the admin console, open Users, find the user, and check the Identity provider links tab (shows entra-id) and the Groups tab (shows the mapped groups).

To send users straight to Entra without the Keycloak login page, add kc_idp_hint=entra-id to the app's login request. The identity provider redirect builder writes the URL for you. If a login fails, turn on Save events under Realm settings → Events → User events settings and look at the Events page for the error details.

Common errors

ErrorCauseFix
AADSTS50011 (redirect URI does not match)The redirect URI in Entra differs from the one Keycloak sends, often a different alias or a missing path segment.Copy the Redirect URI from the Keycloak provider page into Entra. The redirect URI matcher shows the difference.
AADSTS7000215 (invalid client secret)The Secret ID was pasted instead of the Value, or the secret expired.Create a new secret and paste its Value into Client Secret.
AADSTS700016 (application not found in the directory)Wrong client ID, or the discovery URL points to a different tenant.Check the Application (client) ID and the tenant ID in the discovery URL.
AADSTS50105 (user not assigned)Assignment required is on for the enterprise app and the user is not assigned.Assign the user or one of their groups under Users and groups.
Keycloak shows Unexpected error when authenticating with identity provider after the Entra sign-inThe outgoing connection to login.microsoftonline.com is not open yet, or the secret is wrong.Tell us the host through How to reach us. Check the secret.
Group mapper adds nothingThe groups claim is not in the ID token, the user is in more than 200 groups, or Sync mode is Import and this is not the first login.Add the groups claim for the ID token, use Groups assigned to the application, set Sync mode to Force.
Account already exists pageA Keycloak user with the same email already exists.Expected. The user links the accounts by proving they own the existing one.

The OAuth error lookup explains standard OAuth error codes.

FAQ

Can I use the built-in Microsoft provider instead?

It works for basic sign-in when you fill in Tenant ID. It reads the profile from Microsoft Graph instead of the ID token, so the Entra groups claim does not reach Keycloak and the group and role mappers in this guide are not available. It also needs an outgoing connection to graph.microsoft.com.

Can guest users from other organizations sign in?

Yes, if they are guests in your tenant. A single-tenant app accepts members and guests of that tenant. Users of other tenants who are not guests in yours cannot sign in.

How do I rotate the client secret?

Create a new secret in Entra, paste its Value into Client Secret on the Keycloak provider, choose Save, test a login, then delete the old secret in Entra.

Can Keycloak skip its own login page for everyone?

Yes. In Authentication, open the browser flow, choose the gear on Identity Provider Redirector and set Default Identity Provider to entra-id.

Sources

On this page