Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 37 ยท Getting Started

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.

Before you click anything in Keycloak, you need a shared vocabulary. Identity systems use many similar-sounding words, and mixing them up is the source of most early confusion. This lesson defines each term, shows how they fit together and ends with two small experiments.

Identity, authentication, authorization

  • Identity is a set of facts about a subject: a user ID, a name, an email address, the groups they belong to. A subject may also be a program (a service account).
  • Authentication (often shortened to authn) answers "who are you?". The user proves a claim to be a certain identity with something they know (password), have (phone, security key) or are (fingerprint).
  • Authorization (authz) answers "what may you do?". It happens after authentication and compares the identity with rules.

A hotel gives a good picture. Showing your passport at the desk is authentication. The key card that opens only your room (and the gym) is authorization.

A frequent mistake is treating a logged-in user as an allowed user. Being authenticated says nothing about permissions. In Keycloak, authentication is mostly handled in the authentication flows and credentials, while authorization is expressed through roles, groups, scopes and, for advanced cases, Authorization Services.

Factors and MFA

A factor is a type of proof. Multi-factor authentication (MFA) requires two or more different types, so stealing one is not enough.

Factor type Examples
Knowledge Password, PIN
Possession Authenticator app (TOTP), hardware key, phone
Inherence Fingerprint, face

Two passwords are not MFA; they are the same factor twice. Keycloak supports TOTP codes, WebAuthn security keys and passkeys, plus recovery codes.

Sessions and tokens

HTTP has no memory, so after login something must prove "this is still Alice". There are two common models:

  • Session cookie. The server stores the session and gives the browser an opaque ID. Easy to revoke, but every request needs a lookup.
  • Token. The server gives the client a signed piece of data. Any service that knows how to verify the signature can trust it without calling the server.

Keycloak does both: the browser holds a Keycloak SSO cookie for the login session, and applications receive tokens (access token, ID token, refresh token).

Single sign-on (SSO)

SSO means one authentication gives access to many applications. The identity server keeps the session; each application redirects to it, and the server, seeing a valid session, immediately sends the user back with a token, without asking for a password again. Single logout ends the shared session so the other apps stop trusting it.

sequenceDiagram
  participant B as Browser
  participant A as App A
  participant K as Keycloak
  participant C as App B
  B->>A: open App A
  A->>B: redirect to Keycloak
  B->>K: login (password + MFA)
  K->>B: SSO cookie + code for App A
  B->>C: open App B
  C->>B: redirect to Keycloak
  B->>K: request (SSO cookie present)
  K->>B: code for App B, no login form

The second app gets its token without a second login.

Protocols you will meet

Protocol Purpose Format
OAuth 2.0 Delegated authorization: an app gets limited access to an API on a user's behalf Access tokens
OpenID Connect (OIDC) Authentication layered on OAuth 2.0: adds the ID token and a userinfo endpoint JSON, JWT
SAML 2.0 Older XML-based browser SSO, still common in enterprises XML assertions
LDAP A directory protocol for looking up users; Keycloak can federate with it Directory entries

OAuth 2.0 alone is not an authentication protocol: it says an app may call an API, not who the user is. OIDC adds the missing identity layer, and it is what you will use most with Keycloak. Both are detailed in the chapter OAuth2 and OIDC Flows.

Who plays which role

Every OIDC conversation has the same cast. Learn these names; the admin console and documentation use them constantly.

  • Resource owner (the user) owns the data.
  • Client is the application that wants access. In Keycloak, every application is registered as a client.
  • Authorization server issues tokens. In this course: Keycloak.
  • Resource server is the API that accepts tokens.
  • Identity provider (IdP) authenticates users. Keycloak is one, but it can also use others.

Experiment 1: authn is not authz

This stand-in keeps the two ideas separate. Authentication gives a verified identity. Authorization is a separate function that checks rules.

Node.js Stand-in: authentication versus authorization

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.

The output uses the two HTTP status codes you should memorize: 401 means "I do not know who you are", 403 means "I know who you are, and the answer is no".

Experiment 2: why a second factor helps

TOTP codes (the six digits in an authenticator app) come from a shared secret and the current time. Here is the algorithm from RFC 6238 in a few lines, with a fixed time so the output never changes. This is a teaching stand-in, not Keycloak code.

Node.js Stand-in: computing a TOTP code

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.

Because the code changes every 30 seconds and the secret never travels, a phished password alone no longer opens the account.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A user logs in successfully but receives 403 when deleting a record. What does this mean?

    403 means the server knows who you are but refuses the action. A failed authentication would be 401.
  2. 2. Which protocol adds an identity layer (the ID token) on top of OAuth 2.0?

    OIDC extends OAuth 2.0 with the ID token and the userinfo endpoint so that clients learn who the user is.
  3. 3. Which pair counts as true multi-factor authentication?

    Different factor types are required: something you know plus something you have.
  4. 4. In Keycloak terminology, what is a 'client'?

    Every application or API that uses Keycloak is registered as a client.

Summary

  • Authentication proves who you are; authorization decides what you may do. Keep them separate.
  • MFA combines different factor types; Keycloak supports TOTP, WebAuthn and passkeys.
  • SSO keeps one identity-server session shared by many apps; tokens carry the result to each app.
  • OAuth 2.0 authorizes API access, OIDC adds identity, SAML is the older XML option, LDAP is a directory.
  • In Keycloak each application is a client, and Keycloak is the authorization server and identity provider.

Next: Running Keycloak with Docker