What identity brokering is
Keycloak can let users sign in with an account they already have elsewhere: Google, GitHub, Microsoft, another OpenID Connect provider, or a company’s SAML identity provider. Keycloak calls this identity brokering, and each outside provider is an identity provider in the realm.
During that sign-in, Keycloak acts as a client of the outside provider. It sends the user to the provider, and the provider sends them back to Keycloak with a code or an assertion. The address the user comes back to is the redirect URI, and the provider accepts it only if you registered it in advance.
A wrong or missing redirect URI is the most common reason a new "Sign in with" button fails. The provider shows an error page and the user never reaches Keycloak again.
How Keycloak 26 builds the redirect URI
Every identity provider in a realm has an alias. The alias is part of the URL Keycloak uses to receive the response.
https://<host>/realms/<realm>/broker/<alias>/endpointFor a SAML identity provider, the same address is the Assertion Consumer Service URL. Keycloak also publishes service provider metadata for it at the same address with /descriptor added, which you can give to the identity provider instead of typing values by hand.
The host part comes from Keycloak’s hostname setting. If that is wrong, Keycloak sends a different redirect URI from the one you registered, and the provider refuses it.
The alias
When you add a provider, Keycloak suggests an alias equal to the provider’s id, such as google, github or microsoft. You can change it when you create the provider, and you will need different aliases if you add the same kind of provider twice, for example two Microsoft tenants. Treat the alias as permanent: it is part of the redirect URI and of the links between users and the provider, so choose it before you register anything.
What happens during a brokered sign-in
Knowing the order of steps makes errors easier to place. A sign-in through an outside provider runs like this.
- Your app sends the user to Keycloak’s authorization endpoint, as for any sign-in.
- The user picks the provider on Keycloak’s sign-in page, or the app skips that page with the
kc_idp_hintparameter. - Keycloak sends the user to the provider with its own client id and the broker redirect URI.
- The user signs in at the provider, which sends them back to the broker endpoint with a code or a SAML response.
- Keycloak checks the response, finds or creates the matching user through the first broker login flow, and finishes the sign-in.
- Keycloak sends the user back to your app with its own authorization code, and the app gets Keycloak tokens.
Your app never talks to the outside provider. It only ever sees Keycloak’s tokens, so you can add or swap providers without changing the app.
Where each provider wants the URI
Every provider has its own console and its own name for the field. These are the ones built into Keycloak with their default aliases.
| Provider | Default alias | Where to paste the URI |
|---|---|---|
google | Google Cloud console, OAuth client, Authorized redirect URIs | |
| GitHub | github | GitHub OAuth app, Authorization callback URL |
| Microsoft | microsoft | Microsoft Entra app registration, Redirect URI on the Web platform |
| GitLab | gitlab | GitLab application, Redirect URI |
facebook | Meta for Developers, Facebook Login, Valid OAuth Redirect URIs | |
linkedin-openid-connect | LinkedIn Developers app, Authorized redirect URLs | |
| Bitbucket | bitbucket | Bitbucket OAuth consumer, Callback URL |
| OpenID Connect v1.0 | oidc | The provider’s client settings |
| Keycloak OpenID Connect | keycloak-oidc | The other Keycloak’s client, Valid redirect URIs |
| SAML v2.0 | saml | The identity provider, as the Assertion Consumer Service URL |
Provider consoles change their layout from time to time. If a field has moved, look for "redirect", "callback" or "reply URL".
What this tool does
You enter your Keycloak address and realm, pick a provider, and confirm the alias. The tool writes the exact redirect URI to register, and says where it goes in that provider’s settings.
For SAML providers it also gives the metadata URL and Keycloak’s usual service provider entity ID, which is the realm URL. Check that value in the provider’s settings in Keycloak, since it can be changed.
What it does not do
It does not create the identity provider in Keycloak or the app at the provider. It does not know your real alias if you changed it, so it shows the default and lets you edit it. Keycloak itself shows the same redirect URI on the provider’s page once you add it; when in doubt, copy it from there.
How to use it
- Enter your Keycloak’s public address, the same value as the
hostnameoption. - Enter the realm the users will sign in to.
- Pick the provider and check the alias matches the one you use, or will use, in Keycloak.
- Copy the redirect URI and paste it into the provider’s app settings.
- Create the identity provider in Keycloak with the same alias, and fill in the client id and secret from the provider.
- Test the sign-in in a private browser window.
Where it helps
Adding social sign-in to a new app
Teams often set up Google or GitHub sign-in first. Registering the right URI the first time saves a round of errors and support questions.
Connecting a company’s identity provider
For business customers, Keycloak often brokers to the customer’s own Microsoft Entra ID, Okta or another SAML or OIDC provider. Their administrators ask for the redirect URI or metadata URL; send them the exact values from Keycloak.
Moving to a new host or environment
The redirect URI contains the host. When Keycloak moves to a new address, for example from a VM to a Kubernetes cluster with a new domain, every provider needs the new URI. Most providers accept several, so register the new one before the switch and remove the old one after.
Staging and production
Use a separate app at the provider, or at least separate redirect URIs, for each environment. That keeps a staging test from sending users to production.
Common errors and fixes
redirect_uri_mismatch or "invalid redirect URI" at the provider
The URI Keycloak sent is not exactly the one registered. Compare them character by character: scheme, host, port, realm and alias all count, and some providers also compare a trailing slash. The redirect_uri parameter in the provider’s error page or in the browser address bar shows what Keycloak sent.
The URI shows http or an internal host
Keycloak builds the URI from its own address. Set hostname to the public URL, and set proxy-headers if a proxy ends TLS in front of Keycloak. The hostname settings helper walks through it.
Unexpected error when authenticating with identity provider
This generic error usually hides a configuration problem after the redirect: a wrong client secret, a mismatched issuer, or a signature check that failed. The Keycloak server log has the detail.
SAML response rejected
Check that the identity provider sends to the ACS URL above, that the entity IDs match on both sides, and that Keycloak has the provider’s current signing certificate.
Security notes
- Keep the provider’s client secret out of tickets and chat. Store it only in Keycloak.
- Register exact redirect URIs. Avoid wildcards at providers that allow them.
- Decide how accounts are linked. Automatic linking by email trusts that the provider has verified the address; only allow it for providers where that is true.
- Remove redirect URIs for hosts you no longer use, so an old domain cannot be used to receive codes.
Best practices
- Choose short, stable aliases before you register anything, and write them down.
- Use one app per provider per environment.
- Test every provider after a hostname, proxy or domain change.
- Keep the provider list in the realm small. Each extra button is another trust relationship to maintain.