Pcornel
Browse topics
Options
Recent
Favorites
Identity · Technical reference

Keycloak

Direct answer

Keycloak is an open-source identity and access management server. It authenticates users and issues tokens over OpenID Connect, OAuth 2.0 and SAML 2.0, with realms, clients, roles, configurable authentication flows, identity brokering and LDAP/AD user federation.

When to use this

Use it as a self-hosted IdP for your own applications, as an SSO front end to LDAP or Active Directory, or as a broker in front of other identity providers.

First 30 seconds

1. Which realm and client did the application call?

2. Does the issuer in the token match what the application expects (hostname, realm)?

3. Does the redirect URI exactly match a valid redirect URI on the client?

4. Did the user authenticate (event log) and, if federated, can Keycloak bind to LDAP?

Operational verification

application → Keycloak realm (authorization endpoint) → authentication flow (local, LDAP federation or brokered IdP) → session → client scopes and mappers → token → application validates issuer, audience and signature

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Keycloak (Quarkus distribution); kcadm.sh admin CLI.
Applicability is projected only from persisted Topic profile and Command metadata.
At a glance

Operational reference

Fast context before you go deeper.

PlatformKeycloak (Quarkus distribution); kcadm.sh admin CLI.
Scope / prerequisiteUse it as a self-hosted IdP for your own applications, as an SSO front end to LDAP or Active Directory, or as a broker …
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Read-only Verification Verify boundary
# Realm metadata: issuer must match what applications expect
curl -s https://sso.example.com/realms/corp/.well-known/openid-configuration | jq '.issuer, .token_endpoint, .jwks_uri'

# Admin CLI: authenticate against the master realm, then read
kcadm.sh config credentials --server https://sso.example.com --realm master --user admin
kcadm.sh get realms --fields realm,enabled
kcadm.sh get clients -r corp --fields clientId,enabled,protocol,publicClient,redirectUris
kcadm.sh get users -r corp -q username=anna --fields username,enabled,federationLink

A user with a federationLink value comes from LDAP/AD federation; without it, the user is local. In the admin console, Events (enable user events on the realm) records each login with client, IP and error such as invalid_user_credentials or invalid_redirect_uri.

Step 2 Common mistakes Narrow the fault
  • Creating application users and clients in the master realm.
  • Wildcard redirect URIs such as https://* or *.
  • Leaving Direct access grants (password grant) enabled on clients that do not need it.
  • Running start-dev or an embedded development database in production.
  • Changing the public hostname later — every issued token and every application's issuer setting changes with it.
Step 3 Troubleshooting Narrow the fault

"Invalid parameter: redirect_uri". The application sent a redirect URI that does not match any Valid redirect URI on the client — check scheme, host, port, path and trailing slash.

Application rejects the token: wrong issuer. The issuer contains the hostname Keycloak believes it has. Behind a proxy, set the hostname option and forwarded-header handling so Keycloak builds https://sso.example.com/realms/<realm>, not an internal name or port.

LDAP users cannot log in. Use Test connection and Test authentication on the federation provider. Check the bind DN/password, the users DN and search scope, TLS trust for ldaps://, and the username LDAP attribute (sAMAccountName vs userPrincipalName for AD).

Roles missing from the token. The roles are assigned, but no client scope maps them, or the client's Full scope allowed is off and the role is not in its scope. Use the client's Client scopes → Evaluate tab to see the generated token for a user.

Key points

The master realm is for administering Keycloak — put applications and users in their own realm. A client is an application; client scopes decide which claims go into tokens. Every realm publishes its OIDC metadata at /realms/<realm>/.well-known/openid-configuration.

Key checks
  • curl -s https://<host>/realms/<realm>/.well-known/openid-configuration — issuer and endpoints.
  • kcadm.sh get clients -r <realm> --fields clientId,enabled,protocol — which clients exist.
  • Admin console → Realm → Events — login errors with reason (e.g. invalid_user_credentials).
  • Admin console → User federation → Test connection / Test authentication.
ReferenceWhat it is2 sections · depth on demand

Direct Answer

Keycloak is an open-source identity provider. Applications register as clients in a realm; users sign in through Keycloak, which then issues OpenID Connect/OAuth 2.0 tokens or SAML assertions. A realm can hold its own users, read them from LDAP or Active Directory (user federation), or delegate login to another IdP such as Entra ID or Google (identity brokering). Keep the built-in master realm for administering Keycloak and create separate realms for applications.

ReferenceImportant terms & boundaries1 section · depth on demand

In depth

Core concepts

ConceptMeaning
RealmIsolated tenant with its own users, credentials, roles, groups, clients and settings
master realmCreated at first start; holds the initial admin and is used to manage other realms
ClientAn application or service that asks Keycloak to authenticate users or issue tokens
Client scopeReusable set of protocol mappers and role scope mappings; decides which claims a token contains for a requested scope
Realm role / client roleRole valid across the realm / role namespaced to one client
Composite roleRole that includes other roles
GroupUsers inherit the group's attributes and role mappings
Authentication flowConfigurable steps for browser login, registration, reset credentials, direct grant, etc.

Clients

An OIDC client is either confidential (has a secret or key; Client authentication on) or public (browser or native app; must use PKCE). Important settings: Valid redirect URIs (keep exact, avoid wildcards), Web origins for CORS, enabled flows (standard flow = authorization code; direct access grants = password grant, best left off; service accounts = client credentials). A client with service accounts enabled gets its own service-account user to which roles can be assigned.

User federation and brokering

  • LDAP/AD federation — Keycloak validates credentials against the directory and maps attributes and groups. Users can be imported into Keycloak's database or read on demand; edit mode (READ_ONLY, WRITABLE, UNSYNCED) decides whether changes go back to LDAP. Use ldaps:// or StartTLS and a least-privilege bind account.
  • Kerberos — users already logged in to a Kerberos realm can be authenticated with SPNEGO.
  • Identity brokering — Keycloak redirects to an external OIDC or SAML IdP or a social login; identity provider mappers turn the external claims into Keycloak user attributes and roles.

Endpoints

Every realm publishes https://<host>/realms/<realm>/.well-known/openid-configuration with the issuer, authorization, token, userinfo, end-session and JWKS endpoints. SAML clients use the realm's SAML descriptor at /realms/<realm>/protocol/saml/descriptor. Current Keycloak versions serve these paths without the old /auth prefix.

Running Keycloak

The current distribution is configured with kc.sh options, environment variables or conf/keycloak.conf. In production it needs a real database (PostgreSQL, MariaDB, etc.), a stable public hostname (it determines the token issuer) and TLS — either on Keycloak itself or terminated on a reverse proxy that forwards the correct headers. kc.sh start-dev is for development only.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
keycloakkeycloak realmkcadmkeycloak clientkeycloak ldap federation
Confirmation

Confirm action

Continue?