IAM: Keycloak OIDC and Identity Providers
This guide provides detailed, self-service instructions for module developers, administrators, and professional services on integrating applications with Keycloak.
Related Documentation
- This guide focuses on OIDC-based authentication and identity provider setup
- For module-to-module integration (endpoints, permissions, token exchange), see Module Integration with IAM
- 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.
Developer Guide: Integrating a Module with Keycloak
As a developer, your primary goal is to connect your application (module) to Keycloak to handle user authentication.
Checklist for Integration:
Your module will need the following configuration values to communicate with Keycloak:
- Keycloak URL: The base URL of the Keycloak instance (e.g.,
https://keycloak.example.com). - Realm Name: The name of the realm your client is in (e.g.,
supervisory-hub). - Client ID: The ID of the client configured for your module (e.g.,
my-module-client).
Creating a Client Declaratively
The recommended way to configure a client is by adding it to your values.yaml file. This ensures your configuration is version-controlled and repeatable.
For simple, static client configurations, use extraInlineConfig:
keycloak:
extraInlineConfig:
clients:
- clientId: "my-module-client"
name: "My Awesome Module"
enabled: true
protocol: openid-connect
publicClient: false # Set to true for SPAs/front-end apps
standardFlowEnabled: true
redirectUris:
- "https://my-module.example.com/auth/callback"
webOrigins:
- "https://my-module.example.com"
For dynamic configurations that need Helm templating, use extraConfiguration:
keycloak:
extraConfiguration:
my-module-client.yaml: |
realm: {{ .Values.global.keycloak.realm | quote }}
enabled: true
clients:
- clientId: "my-module-client"
name: "My Awesome Module"
enabled: true
standardFlowEnabled: true
redirectUris:
- "https://{{ include "domain.main" . }}/auth/callback"
webOrigins:
- "https://{{ include "domain.main" . }}"
Configuration Methods
For detailed information on both configuration methods (extraInlineConfig and extraConfiguration), including complete examples, comparison, and troubleshooting, see the Extending Keycloak Configuration section.
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 page
Mechanism 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: false
Via 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.
Professional Services Playbook: Onboarding a Customer IDP
This playbook provides a clear, repeatable process for connecting the IAM module to a customer's corporate IDP.
Step 1: Information Gathering (What to ask the customer)
You need the following from the customer's IT/Security team:
- Provider Type: Is their IDP OIDC or SAML?
- Metadata URL / Endpoints: Ask for their OIDC discovery endpoint (
.well-known/openid-configuration) or SAML metadata URL. This often contains all the necessary endpoint URLs. - Client ID & Secret: They will need to create a client registration for Keycloak in their IDP and provide you with the generated Client ID and Secret.
- Attribute Mapping: How should user attributes (e.g., email, first name, last name, groups) from their IDP be mapped to users in Keycloak?
Step 2: Exchanging Configuration (What to provide to the customer)
The customer needs one crucial piece of information from you to complete the registration on their end: the Keycloak Redirect URI.
- Redirect URI Pattern:
{keycloak_url}/auth/realms/{realm_name}/broker/{idp_alias}/endpoint - Example:
https://keycloak.example.com/auth/realms/supervisory-hub/broker/my-corporate-idp/endpoint - You must replace the
keycloak_url,realm_name, andidp_aliaswith your actual values.
Step 3: Implementation and Security
Once you have the customer's information, use the "Administrator Guide" section above to add the IDP configuration to your values.yaml.
- Security Best Practice - Secrets: Always handle customer
clientSecretvalues securely. Use a secrets management tool and reference the secret in yourvalues.yamlrather than pasting it in plain text. - Security Best Practice - Review Claims: Ensure you understand the user attributes (claims) being sent by the customer's IDP and map them correctly.
Step 4: Testing and Validation
- Test the end-to-end login flow.
- When you access your application, you should see a new button on the Keycloak login page (e.g., "Log in with My Corporation").
- Clicking this button should redirect you to the customer's IDP login page.
- After logging in, you should be redirected back to your application, successfully logged in.
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.