IAM: Keycloak OIDC and Identity Providers
This guide provides detailed, self-service instructions for administrators on integrating applications with Keycloak.
Related Documentation
- This guide focuses on OIDC-based authentication and identity provider setup
- For declarative Keycloak configuration (
values.yaml), see IAM Helm Chart Configuration - For chart-managed OAuth client URLs (login callback, web origins, logout), see Keycloak client redirect URIs and web origins
Core Concepts: OIDC Integration
Before integrating a module, it’s important to understand the basics of the OpenID Connect (OIDC) flow that Keycloak uses for authentication.
-
OIDC Flow: When a user tries to access your application, they are redirected to a Keycloak login page. After successful authentication, Keycloak sends them back to your application with a secure token. Your application validates this token to confirm the user’s identity.
-
Key Terms:
- Realm: A dedicated space within Keycloak that manages a set of users, credentials, roles, and clients.
- Client: Represents your application or module that needs to be secured by Keycloak.
- Client ID: A unique identifier for your client within a realm.
-
Redirect URIs: This is a critical security feature. A Redirect URI is a specific URL where Keycloak is allowed to send users back to after they log in. You must register your application’s callback URL in the client configuration to prevent security vulnerabilities. Chart-managed IAM clients use explicit lists under
keycloak.clientUrls; rendering fails when any entry contains*, or when awebOrigins/postLogoutRedirectUrisentry is bare+(Keycloak’s “reuse redirect URIs” shorthand), unless a non-productionallowWildcardsoverride is set.
Administrator Guide: Connecting to External Identity Providers (IDPs)
A common requirement is to allow users to log in with their existing corporate credentials. This is achieved by connecting Keycloak to an external Identity Provider (IDP) like Azure Active Directory, Okta, or any other OIDC/SAML provider.
How it Works (Identity Brokering)
Keycloak acts as a “broker” between your application and the external IDP. When a user logs in, Keycloak redirects them to their company’s login page. After successful authentication, the external IDP sends the user back to Keycloak, which then logs them into your application.
Automated Setup
Identity providers should be configured using extraConfiguration since they typically require dynamic values and complex settings. Add the IDP configuration to your values.yaml:
Example for an OIDC IDP:
keycloak:
extraConfiguration:
identity-provider-corporate.yaml: |
realm: {{ .Values.global.keycloak.realm | quote }}
enabled: true
identityProviders:
- alias: "my-corporate-idp"
displayName: "Corporate Login"
providerId: "oidc"
enabled: true
trustEmail: true
config:
clientId: "client-id-from-customer"
clientSecret: "client-secret-from-customer"
useJwksUrl: "true"
discoveryEndpoint: "https://customer-idp.com/.well-known/openid-configuration"Configuration Methods
For more examples and detailed configuration options, see Extending Keycloak Configuration.
Known Pitfall: Do Not Enable Automatic IDP Login Redirect
Both configurations below bypass the Keycloak login page. Potential issues:
- user is not able to log in as a local account (e.g.,
super_admin) — only the IDP-authenticated identity can log in, - user is not able to log out — the IDP may silently re-authenticate on the next request.
Two mechanisms trigger this — avoid both
Mechanism 1 — authenticateByDefault: true on the IDP
keycloak:
extraConfiguration:
identity-provider-corporate.yaml: |
realm: {{ .Values.global.keycloak.realm | quote }}
enabled: true
identityProviders:
- alias: "my-corporate-idp"
authenticateByDefault: true # skips Keycloak login pageMechanism 2 — Identity Provider Redirector in the browser flow
Via extraConfiguration:
keycloak:
extraConfiguration:
browser-flow-redirect.yaml: |
realm: {{ .Values.global.keycloak.realm | quote }}
enabled: true
authenticatorConfig:
- alias: idp-redirect-config
config:
defaultProvider: "my-corporate-idp"
authenticationFlows:
- alias: browser
providerId: basic-flow
topLevel: true
builtIn: true
authenticationExecutions:
- authenticator: identity-provider-redirector
authenticatorConfig: idp-redirect-config
requirement: ALTERNATIVE
priority: 25
userSetupAllowed: falseVia the Keycloak Admin UI: Authentication → Flows → browser → Add execution → Identity Provider Redirector → Settings → Default Identity Provider.
ALTERNATIVE vs REQUIRED behaves identically when an IDP session is active. The difference is the failure path only: ALTERNATIVE falls back to Keycloak login; REQUIRED blocks all logins entirely.
Why this locks users out
With an infrastructure-level guard (e.g., oauth2-proxy) in front of the app and Keycloak auto-redirecting to the same IDP:
- User logs out of the app → Keycloak session destroyed, broker IDP session terminated.
- Guard session is separate — it stays active.
- User opens the app → guard passes them through (still authenticated).
- Keycloak redirects to the IDP → IDP detects the active guard session → issues token silently.
- User is logged back in as the same account — no prompt, no choice.
Switching to a different account (e.g., a local IAM admin) is impossible without terminating the guard session.
Without a guard
Even with no guard present, an active SSO session from another app in the same organisation causes the same silent re-authentication. The user must explicitly log out of the IDP to switch accounts.
Correct approach
- Keep
authenticateByDefault: false(the default) on every IDP. - Do not add an Identity Provider Redirector execution to the browser flow.
- If IDP enforcement at the app boundary is needed, configure it at the infrastructure level (oauth2-proxy guard) — not inside Keycloak.
Troubleshooting Common Issues
Error: invalid_redirect_uri
- Cause: The application redirected to a URL that is not registered in the
redirectUrislist for that client in Keycloak. After the chart stopped shipping/*, login callbacks other than/oauth2/callbackand logout to any path other than the bare IAM host are rejected unless listed. - Solution: For
oauth-client/api-service-account, add the exact URL tokeycloak.clientUrls. For module or extra clients, list it on that client’sredirectUrisinvalues.yaml. A non-emptyclientUrlslist replaces the default, so/oauth2/callbackand the bare-host post-logout URL must be kept in the list when adding another entry.