Keycloak Azure Ad Identity Provider

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a keycloak azure ad identity provider by linking both tools with OpenID Connect. This link lets users log in to your apps using their Microsoft accounts. Most teams start by making an app record in Microsoft Entra ID. Then they copy the client ID and secret into the Keycloak realm. This setup works well for basic web logins. Still, teams often map broad directory groups to high-level roles. That broad mapping gives users far too much power inside backend systems. How the keycloak az

Keycloak + Azure Privileged Identity Management: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You set up a keycloak azure ad identity provider by linking both tools with OpenID Connect. This link lets users log in to your apps using their Microsoft accounts. Most teams start by making an app record in Microsoft Entra ID. Then they copy the client ID and secret into the Keycloak realm. This setup works well for basic web logins. Still, teams often map broad directory groups to high-level roles. That broad mapping gives users far too much power inside backend systems.

How the keycloak azure ad identity provider workflow runs

The login flow relies on standard trust between the two identity systems. First, a user tries to open an internal app or database tool. Keycloak catches this request and sends the user over to Microsoft. Microsoft checks the user password and runs any multi-factor rules. After the user passes those checks, Microsoft sends a signed token back.

Keycloak reads this token and checks the digital signature against Microsoft keys. If the signature is valid, Keycloak looks for a matching local user profile. When no profile exists yet, Keycloak creates a new user account on the fly. Next, identity mappers read the group claims inside the Microsoft token. These mappers assign local realm roles to the user based on their directory groups. Finally, Keycloak issues its own token so the user can open the target app.

Why role mapping falls short for backend systems

Centralizing logins through Microsoft and Keycloak solves a major daily headache for IT teams. When a worker leaves the company, you disable one Microsoft account. That single action blocks their login across every linked web app right away. You also keep multi-factor rules and password policies in one central place. Auditors like this setup because login events appear in one main log.

Yet this identity link only controls who can pass the front door. Once a user gets a valid token, the identity provider steps out of the way. The native setup cannot see what the user does inside a database or server. A developer might log in with a mapped role that grants write permissions. That role stays active for the whole life of the token.

Identity mappers also struggle with fine-grained rules for daily data tasks. You cannot use a directory claim to block a single bad SQL query. You also cannot use realm roles to hide card numbers or emails in query results. If an engineer runs a wide select statement, the database returns all raw rows. To control actions in flight, you need controls that work at the command level.

Keycloak + Azure Privileged Identity Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Managing group claims and token limits

Large teams often hit size limits when Microsoft sends group data in tokens. If a user belongs to many groups, Microsoft drops the full list from the token. Keycloak then fails to map the expected roles during the login step. Admins must filter the group list in Microsoft so only app groups get sent. Keeping group claims small ensures that role mapping runs fast and stays reliable.

Teams must also watch how both systems handle token lifetimes and logouts. Microsoft tokens and Keycloak sessions each have their own timer settings. If Keycloak holds a long session, a blocked Microsoft user might stay logged in. Admins should set short token lifetimes in Keycloak to force regular checks with Microsoft. You should also turn on backchannel logout so sign-out events sync across both tools.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Most teams pick OpenID Connect because it uses modern JSON tokens and simple URLs. SAML also works well, but XML files take more time to set up and fix.

How do I map Microsoft directory groups to Keycloak roles?

Turn on group claims in your Microsoft app record first. Then add a claim-to-role mapper in Keycloak that matches the Microsoft group ID to a local role.

What happens when you disable a user in Microsoft Entra ID?

Microsoft blocks new logins and token refreshes for that user right away. Active Keycloak sessions will keeps the session active until the current session timer runs out.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.