Skip to content

Keycloak session timeout visualizer

See how access token lifespan, SSO session idle and SSO session max play out over a user’s day, and how often people have to sign in again.

Runs in your browser. Nothing you paste is sent to us.

Realm settings

accessTokenLifespan. Keycloak’s default is 5 minutes.

ssoSessionIdleTimeout. Default 30 minutes.

ssoSessionMaxLifespan. Default 10 hours (600 minutes).

One period per line, as 09:00-12:00. A sample day is filled in.

The day

09:00
Signs in
12:30
Session ends: idle too long
13:15
Signs in again
18:00
Session ends: idle too long
20:00
Signs in again
20:50
Session ends after the last use
Sign-ins
3the user typed a password this many times
Token refreshes
91
Session can last
10 hSSO max, however active the user is
A model of the realm-wide settings, with the app refreshing its token when it expires. A client can set shorter client session idle and max values; remember me and offline tokens follow their own settings. Keycloak also allows a short grace period past the idle time.
An access token stays valid until it expires, even after the session ends, unless your API checks it with introspection. Keep it short.

How to use it

  1. Enter the access token lifespan, SSO idle and SSO max in minutes.
  2. Write down when the user has your app open.
  3. Read the timeline and the list of sign-ins and session ends.
  4. Adjust the values until the day looks right for your users.

What to know

An SSO session ends when nothing has used it for longer than SSO session idle, or when it reaches SSO session max, however active the user is. Each token refresh counts as use.

Access tokens are refreshed when they expire. If the access token lives longer than SSO idle, the session can idle out between two refreshes.

Clients can set shorter session times of their own, and remember me and offline tokens follow separate settings. The tool models the realm-wide values.

Three timers decide when users sign in again

Keycloak keeps a single sign-on session for each signed-in user. Three realm settings decide how long that session and its tokens last: the access token lifespan, SSO session idle and SSO session max. Together they decide how often a user types their password, and how long a stolen token stays useful.

Each timer answers a different question. The access token lifespan says how long an app may call APIs before it needs a fresh token. SSO session idle says how long the session survives without use. SSO session max says how long it may live at all, however active the user is.

SettingRealm JSON fieldDefault
Access token lifespanaccessTokenLifespan5 minutes
SSO session idlessoSessionIdleTimeout30 minutes
SSO session maxssoSessionMaxLifespan10 hours

The realm JSON stores all three in seconds. In the admin console they sit under Realm settings, on the Sessions and Tokens tabs.

Why they matter in production

Set the timers too short and users sign in again several times a day. Support tickets grow, and people start to distrust the sign-in page. Set them too long and a forgotten browser on a shared computer stays signed in for days.

The access token lifespan has a security weight of its own. An access token is usually checked by your APIs from its signature alone. It keeps working until it expires, even after the user signs out or an admin ends the session. A short lifespan limits how long a leaked token is worth anything.

The values also shape load. Shorter access tokens mean more refresh requests to Keycloak. With many active users, that difference shows up in CPU and database load.

How Keycloak 26 tracks a session

When a user signs in, Keycloak creates the SSO session and issues tokens to the app. The app uses the access token until it expires, then sends the refresh token to the token endpoint for a new pair.

Each refresh counts as use of the session and resets the idle timer. Visiting another app that shares the session does the same, because the browser reaches Keycloak with the session cookie. Nothing resets SSO session max: when it is reached, the session ends and the next refresh fails.

A refresh token cannot outlive its session. It expires when the session would idle out or reach its max, whichever comes first. When a refresh fails, the app must send the user back to the sign-in page.

The default values in a sample realm file, in seconds
{
  "realm": "acme",
  "accessTokenLifespan": 300,
  "ssoSessionIdleTimeout": 1800,
  "ssoSessionMaxLifespan": 36000
}

Keycloak also allows a short grace period past the idle time, so a session may end slightly later than the setting says. Do not rely on the exact second.

Client session settings

A client can override the session times for its own sessions, under the client’s Advanced tab. Keycloak uses the shorter of the client and realm values, so an override can only shorten sessions. A value of 0 means the client uses the realm setting.

Remember me and offline tokens

When the realm offers Remember me, sessions created with it can use their own idle and max values. Offline tokens, requested with the offline_access scope, follow separate offline session settings and survive the end of the normal session. Both are outside what this tool models.

What this tool does and does not do

The visualizer takes the three realm settings and a list of times when the user has your app open. It assumes the app refreshes its access token each time it expires while open. It then walks through the day minute by minute.

  • It draws when the app is in use and when a Keycloak session exists.
  • It lists each sign-in and each session end, and why the session ended.
  • It counts sign-ins and token refreshes for the day.
  • It warns when the access token outlives SSO idle, and when SSO idle is longer than SSO max.

It does not model client session overrides, Remember me, offline tokens or the idle grace period. It does not know how your app refreshes tokens: some refresh early, some only on demand, and some keep refreshing in a background tab. Treat the result as a planning aid, then confirm on a test realm.

How to use the visualizer

  1. Enter the access token lifespan, SSO idle and SSO max in minutes. The defaults are filled in.
  2. Write the periods when a typical user has the app open, one per line, such as 09:00-12:00.
  3. Read the timeline: grey bars show the app in use, blue bars show a session.
  4. Read the list of sign-ins and session ends, and the counts below it.
  5. Change one value at a time until the day matches what your users expect.

The sample day has three periods with a lunch break and an evening check. With the defaults, the lunch break is longer than SSO idle, so the user signs in again after lunch.

Choosing values for real apps

There is no single right answer. These are common patterns, not Keycloak defaults.

Office apps used all day

If users take a lunch break and expect to stay signed in, SSO idle must cover the break. A longer idle with a max of a working day gives one sign-in per day. Keep the access token short either way.

Admin consoles and sensitive apps

For tools that change money, data or permissions, shorter sessions are worth the extra sign-ins. Use a client session override for those clients instead of shortening the whole realm.

Customer-facing apps

Shoppers and readers often return after hours or days. Remember me, or longer sessions, may suit them better than a work-day max. Weigh that against shared and public devices.

Mobile apps

Mobile apps often use offline tokens so the user stays signed in across restarts. Offline sessions have their own settings, so plan them separately from the browser session.

Use cases

  • First production deploy: check that the defaults fit your users before launch, not after the first complaints.
  • Upgrade from an older version: compare session settings in the old and new realm exports, so an import does not reset them.
  • Audit: show reviewers how long a session and a token can last, with the day drawn out.
  • Support: reproduce a report of being signed out after lunch by entering the user’s day.

Common problems and fixes

Users are signed out every 30 minutes

That is the default SSO session idle. If the app does not refresh its token or reach Keycloak within that window, the session ends. Raise SSO idle, or make sure the app refreshes while it is open.

Users must sign in again at every refresh

This happens when the access token lives longer than SSO idle. By the time the app refreshes, the session has idled out. Keep the access token lifespan well below SSO idle.

Refresh fails with invalid_grant

The token endpoint answers invalid_grant when the refresh token or its session has expired, or the session was ended. The app should catch this and start a new sign-in instead of retrying.

Signing out does not stop API calls

The access token is still valid until it expires. Keep it short, or have the API check tokens with the introspection endpoint when it must react at once.

Security notes

  • Keep access tokens short. Minutes, not hours.
  • Set SSO session max, so even an active session ends at some point.
  • Use shorter client sessions for admin and payment apps.
  • Remember that offline tokens can live for weeks: grant offline_access only to apps that need it.

Best practices

  • Change one setting at a time and watch sign-in counts.
  • Keep the access token lifespan shorter than SSO idle.
  • Keep session settings in your realm file and version control.
  • Test the result with a real browser on a test realm.
Questions

Frequently asked questions

What are Keycloak’s default session timeouts?

SSO session idle is 30 minutes, SSO session max is 10 hours and the access token lifespan is 5 minutes. All three can be changed per realm under Realm settings.

What is the difference between SSO session idle and SSO session max?

Idle ends a session that nothing has used for that long. Max ends it after that long no matter how active the user is. Token refreshes reset the idle timer, but nothing extends max.

Why are my Keycloak users logged out after 30 minutes?

That is the default SSO session idle. If the app does not refresh its token or reach Keycloak within 30 minutes, the session ends. Raise the value or refresh while the app is open.

How long does a Keycloak refresh token last?

A normal refresh token expires when its session would idle out or reach its max, whichever is sooner. Offline tokens follow the offline session settings instead.

Does logging out invalidate the access token?

No. An access token stays valid until it expires unless your API checks it with introspection. That is why access tokens should be short-lived.

Can one client have shorter sessions than the rest of the realm?

Yes. Set client session idle and max on the client’s Advanced tab. Keycloak uses the shorter of the client and realm values, and 0 means the realm value applies.

Should the access token lifespan be longer than SSO idle?

No. If it is, the session can idle out between two refreshes, and users sign in again at every refresh. Keep the access token well below SSO idle.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.