One realm, one organization per customer
A realm holds your users, your clients and the flows that sign people in. Organizations, fully supported since Keycloak 26.0, divide one realm by customer company. You turn the feature on per realm under Realm settings, then manage each customer under Organizations in the menu.
Each organization holds what one customer needs:
- Its members, added by invitation, by hand, or automatically the first time they sign in through the company’s identity provider.
- Its email domains, such as
customer-a.com. A domain belongs to one organization in the realm. - Its linked identity providers. Since Keycloak 26.8 one provider can be linked to several organizations, each with its own membership settings.
- Its own groups, so each customer’s teams do not collide with another’s.
Your app keeps one client, one issuer and one set of keys. Adding a customer is configuration in the realm, not a new deployment.
Brokering each customer’s identity provider
For each customer, add an identity provider in the realm. For SAML v2.0, import the customer’s metadata by URL or file; for OpenID Connect v1.0, enter their discovery URL, client ID and secret. Then link the provider to the customer’s organization.
The customer needs your side of the connection. For SAML, hand them the service provider metadata Keycloak publishes for that provider:
https://auth.yourcompany.com/realms/your-product/broker/customer-a/endpoint/descriptorFor OpenID Connect, they register https://auth.yourcompany.com/realms/your-product/broker/customer-b/endpoint as the redirect URI in their identity provider.
Then route the domain. On the organization’s Domains tab, pick the identity provider for each domain and turn on Auto redirect. The login page asks for the email first; a user at customer-a.com goes straight to Customer A’s login. A user who already has a password or a passkey in the realm is asked for it instead of being redirected.
Mappers and first login
Identity provider mappers turn what the customer’s provider sends into your user’s attributes and roles: an attribute importer for names and email, a hardcoded role for everyone from that company, or a mapping from a SAML attribute or OIDC claim to a role. The first broker login flow decides what happens the first time someone arrives: create the account, or link it to an existing one after they prove they own it.
What reaches your app
When your client asks for the organization scope, the tokens name the user’s organization:
"organization": {
"customer-a": {}
}Your API checks that claim before it returns a customer’s data. A user who belongs to several organizations picks one at sign-in when the client asks for plain organization, or gets all of them with organization:*. Roles work as usual, and since Keycloak 26.7 a role given to an organization group reaches every member’s token.
Organizations or a realm per customer
| Organizations in one realm | A realm per customer | |
|---|---|---|
| Clients and issuer | One of each for all customers | One per customer, so your app trusts many issuers |
| Login settings | Shared: password policy, sessions, flows | Separate for each customer |
| Adding a customer | A new organization and identity provider | A new realm with its own clients |
| A person in two customers | One account, member of both | Two separate accounts |
| Realms on our plans | One realm covers every customer | 2, 20 or 100 realms, by plan |
Most products start with Organizations. The trade-offs are on Multi-tenant apps.