Keycloak and Identity Management Tutorial
Learn Keycloak and Identity Management step by step: 37 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Keycloak? Open-Source Identity and Access Management Learn what Keycloak is, the problems it solves (login, single sign-on, tokens, roles), how it compares with building auth yourself, and what runs on this site.
- Identity and Access Basics: Authentication, Authorization and SSO Understand the vocabulary behind Keycloak: identity, authentication, authorization, sessions, tokens, SSO, MFA and the main protocols, with runnable stand-ins.
- Running Keycloak with Docker: Your First Server Start Keycloak in a container in dev mode, create the bootstrap admin, persist data with a volume, find the URLs and fix common start-up problems.
- A Tour of the Keycloak Admin Console Walk through the Keycloak admin console menu by menu: realms, clients, users, roles, groups, sessions, events, authentication and realm settings, plus the account console.
Concepts and Setup
- Keycloak Core Concepts: Realms, Clients, Users, Roles and Tokens Learn the Keycloak object model: realm, client, user, role, group, client scope, mapper, session and token, and how they relate, with a runnable model stand-in.
- Installing Keycloak from the Distribution (ZIP, Java, kc.sh) Install Keycloak without Docker: Java requirements, download and unpack, the kc.sh and kc.bat commands, start-dev versus start, build, and a first start checklist.
- Configuring the Keycloak Server: keycloak.conf, Env Vars and CLI Configure Keycloak with CLI arguments, KC_ environment variables and keycloak.conf, understand precedence, secrets, hostname, HTTP, database, logging and health settings.
- Your First Realm, User and Client in Keycloak Create a realm, a user with a password and a client, then request a token with curl and read the discovery document. Includes runnable token-request stand-ins.
Realms, Users and Roles
- Realms in Depth: Isolation, Settings, Keys and Import/Export Understand Keycloak realms: when to use one or many, realm settings, token and session lifetimes, signing keys, brute-force protection and moving realms with export and import.
- Users, Credentials and Password Policies in Keycloak Manage Keycloak users: creation, attributes, user profile, password hashing, password policies, OTP and WebAuthn, temporary passwords, lockouts and the admin REST API.
- Realm Roles, Client Roles and Composite Roles in Keycloak Learn Keycloak role-based access control: realm roles, client roles, composite and default roles, role mapping, how roles appear in tokens and how an API checks them.
- Groups and User Attributes in Keycloak Organize users with Keycloak groups and subgroups, inherit roles and attributes, add the groups claim to tokens, and use attributes for custom data such as department or tenant.
- Required Actions and User Federation (LDAP and Active Directory) Use required actions to verify email, force password changes or set up OTP, and connect Keycloak to LDAP or Active Directory with user federation, mappers and sync modes.
OAuth2 and OIDC Flows
- OAuth 2.0 and OpenID Connect Grants in Keycloak: Overview Compare OAuth 2.0 and OpenID Connect grant types in Keycloak: authorization code with PKCE, client credentials, refresh token, device code and legacy grants, and choose the right one.
- Authorization Code Flow with PKCE in Keycloak Follow the authorization code flow with PKCE step by step: request parameters, state and nonce, code exchange, Keycloak client settings, and a runnable PKCE and state demo.
- Tokens and JWT Claims: Access, ID and Refresh Tokens in Keycloak Decode and validate Keycloak access, ID and refresh tokens: JWT structure, standard and Keycloak claims, JWKS signature checks, lifetimes, introspection and refresh rotation.
- Client Credentials Grant and Service Accounts in Keycloak Secure machine-to-machine calls with the client credentials grant: service account clients, secrets versus signed JWT authentication, roles, caching tokens and rotating credentials.
- Client Scopes and Protocol Mappers: Shaping Keycloak Tokens Control what goes into Keycloak tokens with client scopes and protocol mappers: default and optional scopes, built-in mappers, audience, hardcoded claims and full scope.
Identity Brokering and Social Login
- Identity Brokering Explained Learn how Keycloak brokers logins to external identity providers, what first login does, how accounts are linked, and which flows and settings control it.
- Social Login with Google and GitHub Set up Google and GitHub social login in Keycloak: create the OAuth app, copy the redirect URI, enter client ID and secret, map attributes, and debug failures.
- External OIDC and SAML Identity Providers Connect Keycloak to a corporate OpenID Connect or SAML 2.0 identity provider: discovery import, metadata exchange, claim and attribute mappers, and role mapping.
- LDAP and Active Directory User Federation Connect Keycloak to LDAP or Active Directory with user federation: connection settings, edit modes, import and sync, LDAP mappers, filters and Kerberos.
Authorization Services
- Authorization Services Concepts Understand Keycloak Authorization Services: resource servers, resources, scopes, policies and permissions, and how they differ from simple role checks.
- Policies, Permissions and Decision Strategies Learn Keycloak policy types (role, user, group, time, regex, aggregate), permission types, logic Positive and Negative, and the Unanimous, Affirmative, Consensus strategies.
- RPTs and Policy Enforcement Request permissions from Keycloak with the UMA grant, read the RPT permissions claim, choose decision or permissions response modes, and enforce them in an API.
Customization
- Themes and Custom Login Pages Customize Keycloak with themes: theme types, folder layout, theme.properties inheritance, FreeMarker templates, message bundles, CSS, and deploying a custom login theme.
- Custom Authenticators and Keycloak SPIs Extend Keycloak with Service Provider Interfaces: authentication flows and executions, writing a custom authenticator, factory registration, packaging, and flow requirement logic.
- Protocol Mappers and Custom Claims Add custom claims to Keycloak tokens: client scopes, protocol mapper types, user attribute and role mappers, audience claims, nested claim names, and where each claim lands.
- User Profile and Required Actions Configure the Keycloak declarative user profile: attributes, validators, permissions, groups of fields, and required actions such as verify email, update password and terms.
Deployment and Operations
- Production Configuration Configure Keycloak for production: kc.sh start vs start-dev, hostname, TLS, reverse proxy headers, the build step, option precedence, environment variables and admin hardening.
- Database and Clustering Plan the Keycloak database and a multi-node cluster: supported databases, connection pools, Infinispan caches, session ownership, discovery, load balancing and sizing.
- Monitoring, Events and Metrics Monitor Keycloak in production: login and admin events, event listeners, Prometheus metrics, health endpoints, logging, brute force detection and useful alerts.
- Backup, Export and Upgrades Protect Keycloak data with database backups and realm exports, import configuration safely, and plan upgrades with tested rollbacks, migration order and checklists.
Projects and Practice
- Project: A Single-Page App with PKCE Build the Authorization Code with PKCE flow for a single-page app against a Keycloak client, with a runnable in-memory mock server that shows every request and check.
- Project: A JWT Verifier for Your API Build a token verifier for a resource server: fetch JWKS, verify RS256 signatures, check iss, aud, exp and roles, with a runnable example using WebCrypto and a generated key.
- Project: Designing a Multi-Tenant Setup Choose between one realm per tenant, a shared realm with groups, or Keycloak Organizations. A design project with a decision scorer, naming rules and per-tenant login routing.
- Security Hardening Audit Audit a Keycloak realm for common weaknesses: SSL required, brute force, password policy, redirect URIs, public clients, token lifetimes, MFA and admin exposure, with a checker script.