What Is a Client Session in Keycloak?

What Is a Client Session in Keycloak?

A complete, beginner-friendly walkthrough of Keycloak's client sessions — how they relate to the broader user session, how single sign-on actually works underneath, and how logout ripples across every connected app.

Picture a university student carrying one main ID badge for the whole campus, but each building they enter — the library, the gym, the cafeteria — separately logs the exact moment that particular badge tapped in at that particular door. The badge itself represents one overall “I’m on campus” status. Each building’s own tap-in record represents something narrower: this specific badge, at this specific building, right now. Keycloak’s client session plays exactly that second role. It’s the record of one particular application’s relationship with a user who is already signed in more broadly through Keycloak. This post walks through what a client session actually is, how it relates to the bigger user session behind it, and why understanding this distinction explains a lot of Keycloak’s single sign-on and logout behavior.

1What Is a Client Session, Really?

Before opening the admin console, let’s fix the plain-English idea in place.

In Keycloak, when a user logs in, two related but distinct things get created behind the scenes: a user session, representing the fact that this person is authenticated with Keycloak at all, and one client session for every specific application the user then goes on to access during that same login. A client session is the record of one particular client application’s relationship with an already-authenticated user — tracking things like which client it belongs to, what was granted, and when this specific application was last active.

The relationship is one-to-many: a single user session can have several client sessions hanging off it at once, one per application the user has touched since logging in. Log into Keycloak once, then visit three separate applications that all trust the same realm, and you typically end up with one user session and three client sessions underneath it.

Simple Analogy

Think of a hotel guest’s key card as the user session — proof they’re a checked-in guest of the hotel. Each time they use that card to enter a specific amenity — the pool, the gym, the parking garage — the amenity’s own access log entry for that visit is like a client session: tied to the same guest, but recording that particular facility’s own interaction with them.

i
Where you’ll see this in practice

Keycloak’s admin console shows this relationship directly: opening a user’s “Sessions” tab lists their user sessions, and expanding one reveals every client session nested underneath it.

2Client Session vs. User Session

These two terms are easy to confuse, so it’s worth putting them side by side.

AspectUser SessionClient Session
RepresentsThe user’s overall authenticated presence in the realmOne specific client’s relationship with that authenticated user
Created WhenThe user first logs in to the realmThe user first accesses a given client during that login
CardinalityOne per active loginMany per user session — one per client used
PowersSingle sign-on across the realmPer-application token issuance and per-application logout

Neither one is useful entirely on its own. The user session alone can’t tell you which specific applications a person is actively using, and a client session alone can’t exist without a parent user session backing it — every client session is always tied back to exactly one user session.

!
Common Misconception

Logging into one application and logging into Keycloak are not the same event from a session-modeling point of view — the first login creates the user session, and each application accessed afterward creates its own, separate client session.

3Why This Two-Layer Model Exists

This split isn’t accidental complexity — it’s the exact mechanism that makes single sign-on and clean logout possible.

If Keycloak only tracked one flat session per user, there would be no natural way to answer questions like “which applications has this user actually used during this login?” or “can I log this user out of just one application, without touching the others?” By separating the broad user session from the many narrower client sessions beneath it, Keycloak gets a natural home for both realm-wide concerns (like the overall SSO session timeout) and per-application concerns (like which specific app to notify during logout).

The foundation of Single Sign-On

Because the user session already exists once a user logs in anywhere, visiting a second application that trusts the same Keycloak realm doesn’t require a fresh login — Keycloak simply creates a new client session under the existing user session instead.

4How a Client Session Gets Created

Here’s the moment-by-moment sequence behind the scenes.

flowchart TD
    A["User visits App A"] --> B{"User session
already exists?"} B -- No --> C["User logs in
User Session created"] B -- Yes --> D["SSO — no login prompt needed"] C --> E["Client Session created
for App A"] D --> E E --> F["Tokens issued to App A"] F --> G["User later visits App B"] G --> H["New Client Session created
for App B, under same User Session"]
FIG 1 — The user session is created once; a new client session is added each time a different application is accessed for the first time in that login.

Notice that visiting App B doesn’t require App A’s client session to be touched at all — the two client sessions coexist independently, both anchored to the same underlying user session.

5What a Client Session Actually Stores

A client session isn’t just a marker that says “this app was used” — it carries meaningful state of its own.

Identity

Client Reference

Which specific client this session belongs to, linking it back to that client’s configuration in the realm.

Protocol State

Redirect & Protocol Notes

Details like the redirect URI used and protocol-specific notes needed to correctly continue or refresh tokens for this client.

Timing

Timestamps

When this particular client session started and was last refreshed, used to evaluate its own idle and expiration behavior.

Consent Context

Granted Scopes

Which scopes were actually requested and granted for this specific client during this session.

This is why a client session matters beyond bookkeeping: it’s the anchor Keycloak uses every time that specific application needs to refresh a token, and it’s the specific record that gets invalidated if that one application is logged out individually.

6Client Sessions and Access Tokens

Tokens and sessions are related but not identical concepts, and the client session sits right at that boundary.

An access token is a self-contained, short-lived credential — once issued, Keycloak doesn’t necessarily need to look anything up to validate it, as long as its signature and expiry check out. A refresh token, by contrast, works by pointing back at a session record. When a client presents a refresh token to get a new access token, Keycloak looks up the corresponding client session (and its parent user session) to confirm it’s still valid before issuing anything new.

Simple Analogy

An access token is like a paper concert wristband — once it’s on your wrist, the bouncer doesn’t need to call anyone to let you back in, as long as it hasn’t been cut off or expired. A refresh token is more like a claim ticket that only works if the counter still has a matching record on file — and the client session is exactly that record.

7Client Session Lifecycle & Timeouts

A client session’s lifespan is shaped by both its own settings and the boundaries of its parent user session.

A client session can never outlive its parent user session — once the overall user session ends, every client session beneath it ends too, automatically. Within that boundary, individual client timeouts and activity also matter: if a particular client session sits idle without being used to refresh a token, it can expire on its own, even while the broader user session and other client sessions under it remain active.

1
user session sets the outer boundary
N
client sessions can live and die independently within it
0
client sessions survive their parent user session ending
i
Practical Tip

This is why a user can stay “logged in” overall while one rarely used application’s own session quietly expires in the background — the next visit to that app simply triggers a fresh client session under the still-valid user session, with no full re-login required.

8Storage & Clustering

Where this session data actually lives matters once Keycloak runs across more than one server.

Client sessions, like regular user sessions, live primarily in Keycloak’s distributed in-memory cache (Infinispan), replicated across cluster nodes so any node can serve a request for an active session without a single point of failure. This is different from offline sessions, which are deliberately persisted to the database so they can survive far longer than any in-memory cache is designed to hold data.

Why this design choice makes sense

Regular client sessions are expected to be relatively short-lived and tied to active usage, so fast, replicated in-memory storage is a better fit than the heavier persistence used for offline sessions, which are explicitly designed to outlive normal usage patterns.

9Logout: Where Client Sessions Really Matter

The client-session model is what makes both full logout and selective logout possible.

sequenceDiagram
    participant U as User
    participant K as Keycloak
    participant A as App A
    participant B as App B

    U->>K: Initiates logout
    K->>K: Find User Session
    K->>K: Find all Client Sessions under it
    K->>A: Back-channel logout notification
    K->>B: Back-channel logout notification
    A-->>K: Session invalidated locally
    B-->>K: Session invalidated locally
    K->>K: Terminate User Session
    K-->>U: Logout complete across all apps
        
FIG 2 — A full logout walks through every client session under the user session, notifying each application individually.

This is the mechanism behind Single Logout (SLO): because Keycloak knows exactly which client sessions exist under a given user session, it can notify every one of those applications — often through a back-channel logout request — so each can clean up its own local state, rather than relying on the user manually logging out of every application one by one.

Selective, per-application logout

Because each client session is tracked independently, an administrator (or, in some setups, the application itself) can end just one client session without disturbing the user’s broader login or their sessions with other applications.

10Security Considerations

Because client sessions sit at the heart of both SSO and logout, a few practices keep that machinery trustworthy.

Logout Reliability

Implement back-channel logout properly

An application that doesn’t correctly handle Keycloak’s back-channel logout notifications may keep functioning locally even after its client session has ended, undermining the point of SLO.

Idle Behavior

Set sensible client-level timeouts

Idle client sessions that never expire can leave a longer-than-intended window where a token refresh remains possible for an application nobody is actively using.

Session Visibility

Give administrators clear session views

Being able to see exactly which client sessions exist under a suspicious user session helps administrators respond quickly during an incident.

ANTI-PATTERN-01 Avoid
Problem

An application ignores Keycloak’s back-channel logout calls and only clears its own local session cookie when the user manually clicks its own logout button.

Why It’s Harmful

A user who logs out through a different application, or through an administrator-triggered session termination, may still appear “logged in” to this application, defeating the purpose of centralized single logout.

Correct Approach

Implement the logout notification handling Keycloak’s adapters or standard protocols provide, so the application’s own local state stays in sync with its client session’s real status.

11Advantages, Disadvantages & Trade-offs

The two-layer session model is elegant, but it does add a bit of conceptual overhead.

Advantages

  • Enables true single sign-on across many applications sharing one realm
  • Supports both full, realm-wide logout and precise, per-application logout
  • Lets administrators see exactly which applications a user has actively used during a login
  • Keeps per-application state (like granted scopes) cleanly separated per client

Disadvantages / Trade-offs

  • Adds a genuine extra concept for newcomers to Keycloak’s session model to learn
  • Requires applications to correctly implement logout notifications to fully benefit from SLO
  • More sessions to track means more state a clustered deployment has to replicate

12Design Patterns & Anti-Patterns

A few recurring habits distinguish teams who work smoothly with this model from those who get tripped up by it.

Pattern: Treat the Admin Console’s Session View as a Diagnostic Tool

When investigating “why is this user still logged in” or “why did this app log the user out,” start by inspecting the user session and its client sessions directly.

Pattern: Align Client Timeouts with Real Usage Patterns

Set a client’s own session timeout expectations based on how that specific application is actually used, rather than copying the realm-wide defaults unthinkingly.

ANTI-PATTERN-02 Avoid
Problem

Assuming that ending one application’s own local session automatically ends the user’s broader Keycloak session, or vice versa.

Why It’s Harmful

This misunderstanding leads to confusing bug reports like “I logged out of one app but I’m still logged into everything else” — which, given the model, is often expected behavior rather than a bug.

Correct Approach

Be explicit about which kind of logout an action performs — single-client versus full single logout — both in application design and in communicating behavior to end users.

13Best Practices & Common Mistakes

A short, practical checklist for teams building or debugging applications on top of Keycloak’s session model.

1

Implement logout notification handling

Ensure every client application correctly responds to Keycloak’s logout notifications so its local state matches its client session’s real status.

2

Distinguish user-session and client-session settings

When tuning timeouts, be clear about whether a setting affects the whole realm’s user sessions or one specific client’s sessions.

3

Use the admin console’s session tools during incidents

Inspecting and, if needed, terminating specific client sessions gives a precise response option short of ending a user’s entire login.

!
Common Mistake

Assuming a single “session timeout” setting governs everything — Keycloak actually distinguishes realm-level user session timeouts from client-specific session behavior, and conflating the two leads to misconfigured expectations.

14Real-World Use Cases

The client session model quietly powers everyday experiences across many kinds of deployments.

Enterprise Suites

Multiple Internal Applications

An employee logging into one internal tool can move seamlessly into several others without re-authenticating, thanks to shared user sessions and per-app client sessions underneath.

Customer Portals

Coordinated Logout

A “log out everywhere” button in a customer-facing portal relies on Keycloak walking every client session under the user’s session and notifying each connected application.

Security Response

Targeted Session Termination

An administrator responding to a compromised device can end just the specific client session tied to that device’s application, without forcing a full re-login everywhere else.

15Monitoring, Logging & Metrics

Because session behavior is central to both user experience and security, visibility into it is valuable.

Track active client session counts per client

An unusually high count for one client can point to a bug causing repeated re-authentication or, in rarer cases, misuse.

Log logout notification failures

If a client application repeatedly fails to acknowledge back-channel logout calls, that’s worth surfacing, since it undermines single logout guarantees.

Watch for orphaned or unusually long-lived client sessions

A client session that persists far longer than expected relative to its configured timeout can indicate a configuration issue worth investigating.

16Frequently Asked Questions

Q1Can a client session exist without a user session?

No. Every client session is always tied to exactly one parent user session, and it’s automatically terminated when that user session ends.

Q2Can one user have two client sessions for the same application at once?

Generally, one client session per client per user session is the standard model, representing that application’s single relationship with the user during that login.

Q3Does logging out of one application always log the user out of everything?

Not necessarily. Whether a logout ends just one client session or the entire user session (and all client sessions under it) depends on which type of logout is triggered.

Q4Where can an administrator view active client sessions?

In the Keycloak admin console, under a user’s Sessions tab, or under a specific client’s own Sessions view, both of which reflect the same underlying data from different angles.

Q5Are client sessions the same thing as offline sessions?

No. Regular client sessions live in fast, in-memory storage and are tied to normal SSO behavior, while offline sessions are deliberately persisted to the database to survive far longer, independent of the standard client-session lifecycle.

Q6What happens to a client session if its access token expires?

Nothing happens to the client session itself just because an access token expires — the client session remains valid and can be used to obtain a fresh access token via the refresh token, as long as its own timeout hasn’t been reached.

17Summary and Key Takeaways

A client session is Keycloak’s record of one specific application’s relationship with an already-authenticated user, nested under that user’s broader user session. This two-layer design is what makes single sign-on across many applications possible, gives administrators precise visibility into exactly which apps a user has touched during a login, and enables both full single logout and targeted, per-application session termination. Understanding the difference between a user session and the client sessions living beneath it clears up a surprising amount of confusion about how Keycloak-backed logins and logouts actually behave in practice.

Key Takeaways

  • It’s nested under a user session — one user session, potentially many client sessions beneath it.
  • One per application, per login — created the first time a specific client is accessed during a session.
  • It powers Single Sign-On — a new client session, not a new login, is created when visiting an already-trusted second application.
  • It anchors refresh tokens — Keycloak looks up the client session behind a refresh token before issuing a new access token.
  • It can’t outlive its parent — ending the user session automatically ends every client session beneath it.
  • It’s central to logout behavior — enabling both realm-wide Single Logout and precise, per-application session termination.
  • It lives in fast, replicated storage — distinct from the database-persisted model used for offline sessions.