Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท 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.

Almost every application needs the same three things before it does anything useful: a way to log users in, a way to remember who they are, and a way to decide what they may do. Writing this yourself for every app means writing it again and again, and every copy is a chance for a security bug. Keycloak is an open-source server that does these jobs once, for all your applications.

Keycloak is an identity and access management (IAM) product. It is a Java application, started in 2013 by Red Hat and now a project of the Cloud Native Computing Foundation. It speaks the standard protocols (OpenID Connect, OAuth 2.0 and SAML 2.0), so your apps do not need Keycloak-specific code to talk to it. You can run it on a laptop, in a container, or in a Kubernetes cluster.

What runs on this site. Keycloak is a server with its own database and web console, and it cannot run inside your browser. In this course every Keycloak menu, command and configuration is described precisely, but never shown as fake output. To practice the ideas (tokens, PKCE, role resolution, password policies) the lessons use small runnable stand-ins written in JavaScript. Each one is labelled "stand-in" and teaches the same logic Keycloak implements. To use the real product, follow the commands in Running Keycloak with Docker on your own machine.

The problem Keycloak solves

Imagine a company with a web shop, an admin dashboard and a mobile app. Without a central identity server, each one has its own user table and its own login form:

  • Users have three passwords, and forget all of them.
  • Each app implements password hashing, reset emails and lockouts on its own, with different bugs.
  • Adding "sign in with Google" or two-factor authentication means changing three code bases.
  • When someone leaves the company, three accounts must be disabled.

With Keycloak, the apps delegate login. When a user opens an app, the app redirects them to Keycloak. Keycloak shows the login page, checks the password (and a second factor if required), and sends the user back with a signed token that says who they are. The app only has to verify that token.

What Keycloak gives you

Login Forms, passwords, MFA, passkeys.
Single sign-on Log in once, use every app.
Tokens Signed proof of identity.
Access control Roles, groups, policies.

One server, many applications.

1 / 2

Core features at a glance

  • Single sign-on (SSO) and single logout. One login covers all apps in a realm; logging out in one place ends the session everywhere.
  • Standard protocols. OpenID Connect (OIDC) for modern web and mobile apps, OAuth 2.0 for API access, and SAML 2.0 for older enterprise software.
  • User management. An admin console and a REST admin API to create users, reset passwords, assign roles and group people.
  • Identity brokering. Let users sign in with an external identity provider (Google, GitHub, a corporate SAML provider) while your apps still see only Keycloak.
  • User federation. Read users from LDAP or Active Directory instead of copying them.
  • Strong authentication. One-time passwords (TOTP), WebAuthn security keys and passkeys, conditional flows.
  • Fine-grained authorization. Roles for simple cases; Authorization Services (resources, scopes, policies, permissions) for complex ones.
  • Customization. Themes for the look, and Java Service Provider Interfaces (SPIs) to extend behavior.

Keycloak is not your application

Keycloak answers "who is this?" and "what is this person allowed to do in general?". It does not run your business logic. Your application still decides, for example, whether this user may edit this invoice. Keycloak supplies the trusted facts (a verified user ID, roles, groups) and your code uses them.

flowchart LR
  U["User's browser"] -->|"1. open app"| A["Your application"]
  A -->|"2. redirect to login"| K["Keycloak"]
  U -->|"3. enter credentials"| K
  K -->|"4. redirect back with code"| A
  A -->|"5. exchange code for tokens"| K
  A -->|"6. serve page for the user"| U

The delegation pattern: the application never sees the password.

Keycloak or build it yourself?

Building authentication from scratch looks easy until you need password resets, rate limiting, brute-force protection, MFA, email verification, session management, account linking, token rotation and an audit log. Most of that is security-critical, and security-critical code is the wrong place to be creative.

Option Good for Watch out for
Framework login (for example a built-in session login) One application, simple needs Hard to share between apps
Keycloak (self-hosted) Several apps, SSO, control over data, no per-user fee You operate the server: upgrades, backups, availability
Hosted identity service Teams that do not want to operate anything Per-user pricing, data lives with a vendor

Keycloak is free to use, but not free to run. Plan for a database, backups, monitoring and regular upgrades (see the chapter on deployment).

A tiny single sign-on model

The idea behind SSO is simple: the identity server keeps one session per user, and every app asks it for proof. This runnable stand-in is not Keycloak. It is about thirty lines that model the same flow, so you can see why logging in once is enough.

Node.js Stand-in: single sign-on in 30 lines

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Notice that the dashboard never asked for a password: the shared session did the work. Real Keycloak adds signed tokens, per-client sessions, expiry and back-channel logout, and you will meet each in later lessons.

Node.js Stand-in: what a token adds

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

A tampered token fails verification, so an app can trust the claims without asking the server again. Real tokens are JWTs signed with asymmetric keys, covered in Tokens and JWT Claims.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main job of Keycloak?

    Keycloak is an identity and access management server. Applications delegate login to it and receive tokens.
  2. 2. Which standard protocols does Keycloak support out of the box?

    Standards-based integration means apps can use any OIDC, OAuth 2.0 or SAML library instead of Keycloak-specific code.
  3. 3. In the delegation pattern, who sees the user's password?

    The app redirects to Keycloak for login, so the password only ever goes to the identity server.
  4. 4. Which is a real cost of self-hosting Keycloak?

    The software is free, but running a security-critical service reliably is your responsibility.

Summary

  • Keycloak is an open-source identity and access management server that handles login, SSO, tokens and access control for many applications.
  • Apps delegate authentication to it using OIDC, OAuth 2.0 or SAML, so they never handle passwords.
  • Beyond login it offers brokering, LDAP federation, MFA, fine-grained authorization, themes and extension points.
  • It supplies trusted facts about the user; your application still enforces its own business rules.
  • You trade the work of writing auth for the work of operating a server.

Next: Identity and Access Basics