Keycloak Add Microsoft Identity Provider

Published
Length
3 min read

Luis Felipe Dias

All posts

To run the keycloak add microsoft identity provider setup, register an app in Microsoft. Then copy the client ID and secret into your Keycloak realm. Teams do this to let staff log in with their work accounts. It stops teams from making new passwords for each internal tool. Still, teams often map broad Microsoft groups to wide admin roles. This gives too many users full control over sensitive systems. How the keycloak add microsoft identity provider workflow runs First, an admin creates a new

Keycloak + Identity Provider Integration: the complete guide

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

Free white paper. No spam. Unsubscribe anytime.

To run the keycloak add microsoft identity provider setup, register an app in Microsoft. Then copy the client ID and secret into your Keycloak realm. Teams do this to let staff log in with their work accounts. It stops teams from making new passwords for each internal tool. Still, teams often map broad Microsoft groups to wide admin roles. This gives too many users full control over sensitive systems.

How the keycloak add microsoft identity provider workflow runs

First, an admin creates a new app registration in the Microsoft cloud portal. Microsoft gives you a unique client ID and a client secret key. Next, you open your Keycloak realm settings and pick Microsoft as a provider. You paste the ID and secret key into the provider fields. Keycloak then gives you a redirect URL to copy back into Microsoft.

When a user clicks log in, Keycloak sends them to the Microsoft login page. The user enters their work email, password, and multi-factor code there. Microsoft checks the user and sends a signed token back to Keycloak. Keycloak reads the token and creates a local session for that user. You can also set up mappers to read Microsoft group claims. These mappers attach local Keycloak roles to the user profile during login.

Why identity login alone leaves a gap

Linking Microsoft to Keycloak solves the problem of who can log in. Your team gets one place to turn off accounts when staff leave. You also keep multi-factor rules in one central place for all users. This works well for basic web apps that use simple role checks.

Yet this setup leaves a big gap for database and server tasks. Login checks only happen at the start of a user session. Once a user gets a role, Keycloak steps out of the way. It cannot see what queries a user runs inside a database. It also cannot check which commands an engineer types on a host. If a user maps to a broad role, they keep that power all day. A single bad query can still drop a table or expose card numbers.

Keycloak + Identity Provider Integration: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Moving from static group roles to action checks

Most teams start by mapping a Microsoft group to a database role. For example, every backend engineer gets the same read and write role. Over time, these shared roles grow too large to track or fix. Nobody wants to break an app by taking away a group role.

To fix this, teams must separate login identity from live session power. Keep using Microsoft and Keycloak to prove who a user is. Then check each action at the moment the user runs a command. This stops users from holding high power when they do not need it. You can also mask emails or phone numbers in query results right away. That way, identity checks pair with real control over every single command.

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

Can I map Microsoft groups to Keycloak roles?

Yes, you can add a claim mapper inside your Keycloak identity provider settings. The mapper reads group IDs from the Microsoft token and assigns local roles.

What happens when a user leaves the Microsoft directory?

When you block the user in Microsoft, they cannot get new tokens. Their next login attempt through Keycloak will fail right away.

Does Keycloak log the database queries a user runs after login?

No, Keycloak only handles the login flow and issues identity tokens. It does not see or log commands sent to databases or servers.

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.