Skip to content

Realms, Clients & Roles

This module teaches the three building blocks that every Keycloak deployment is made of: realms, clients, and roles. Before you can secure a single application with Keycloak, you need to understand what these concepts are, how they relate to each other, and how to create and configure them in the admin console.

By the end of this module you will be able to:

  • Create and configure a dedicated realm for your application.
  • Register an application (client) with Keycloak.
  • Understand the difference between public and confidential clients and choose the right one.
  • Create realm roles and client roles and assign them to users.
  • Read a decoded JWT and find roles inside it.

A realm is Keycloak’s top-level isolation boundary. Think of it as a tenant: it has its own set of users, clients, roles, identity providers, and token settings. Nothing leaks between realms — a session in realm A cannot authenticate a user into realm B.

Keycloak ships with one realm pre-created: master. The master realm is the administrative realm — you use it to log in to the admin console and manage other realms. You should never deploy your own applications inside the master realm.

A client is any application that delegates authentication to Keycloak. A client could be a single-page app (SPA), a mobile app, a server-side web application, or a machine-to-machine service. Each client registers itself in a realm, declares its redirect URIs, and receives tokens from Keycloak after a user authenticates.

A role is a named permission that can be attached to users or groups. There are two flavours:

  • Realm roles — defined at the realm level and available to any client in that realm.
  • Client roles — defined on a specific client and scoped to that client.

Roles show up in tokens so your application can make authorisation decisions without calling Keycloak again.

flowchart TD
  R[Realm] --> U[Users]
  R --> RR[Realm-level roles]
  R --> C[Clients]
  C --> CR[Client roles]
  C --> RU[Valid redirect URIs / settings]
How a realm contains users, roles, and clients

A user in a realm can be assigned realm roles and client roles. When the user authenticates through a client, the resulting token contains those roles so the client can enforce access control.

LessonWhat you will learn
RealmsCreate and configure a realm
ClientsRegister an application as a client
Client TypesPublic vs confidential clients and PKCE
RolesRealm roles, client roles, and composite roles
What is a Keycloak realm?
Which realm should you use to host your own application?
What is the difference between a realm role and a client role?