Skip to Content
IAM
Module Integration
IAM: Keycloak OIDC and Identity Providers

IAM: Keycloak OIDC and Identity Providers

This guide provides detailed, self-service instructions for administrators on integrating applications with Keycloak.

Note

Related Documentation

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 a webOrigins / postLogoutRedirectUris entry is bare + (Keycloak’s “reuse redirect URIs” shorthand), unless a non-production allowWildcards override 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:

values.yaml
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"
Note

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.
Caution

Two mechanisms trigger this — avoid both

Mechanism 1 — authenticateByDefault: true on the IDP

values.yaml — anti-pattern
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:

values.yaml — anti-pattern
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:

  1. User logs out of the app → Keycloak session destroyed, broker IDP session terminated.
  2. Guard session is separate — it stays active.
  3. User opens the app → guard passes them through (still authenticated).
  4. Keycloak redirects to the IDP → IDP detects the active guard session → issues token silently.
  5. 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.

Note

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.

Tip

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 redirectUris list for that client in Keycloak. After the chart stopped shipping /*, login callbacks other than /oauth2/callback and 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 to keycloak.clientUrls. For module or extra clients, list it on that client’s redirectUris in values.yaml. A non-empty clientUrls list replaces the default, so /oauth2/callback and the bare-host post-logout URL must be kept in the list when adding another entry.