Keycloak token and session lifetime settings

How to choose Keycloak access token, SSO session, client session and offline session lifetimes by application risk, and what each choice does to logout and user experience.

On this page

Keycloak token and session lifetime settings: how to choose them by risk

If you are a security or platform lead who must decide how long Keycloak tokens and sessions last across many applications, start by grouping those applications by risk, then set lifetimes for each group instead of one value for the whole realm. Short access tokens and session limits reduce the window in which a stolen token or an unattended browser stays useful, while longer lifetimes reduce sign-in friction for low-risk tools. The right answer comes from what each application can access and how it handles tokens, not from a single default. Keycloak sets these lifetimes at two levels. Realm settings define the baseline for access tokens, SSO session idle and maximum timeouts, client session timeouts and offline session behavior. Client settings can override several of those values for one application, so a finance portal and an internal wiki in the same realm can behave differently. Because these values interact, a short access token does little if the SSO session behind it lasts for days, and a generous client session can extend a session that the realm was meant to end. Review them together, not one field at a time.

Tune lifetimes when you onboard a new class of application, when a finding or incident shows that sessions outlive their purpose, or when a regulator or internal policy asks you to show how session length is controlled. Before you change anything, confirm the current values in your own realm export and in each client, because defaults can differ between releases and between distributions, and check the Keycloak server administration guide for the exact meaning of each field in your version. Record the chosen values per application group, test sign-out and re-authentication for each group, and keep the evidence with your change record so that the settings can be explained later.

Which lifetime setting fits which application risk

This table compares the main Keycloak lifetime settings, what each one controls, and how it should be set for high-risk, standard and low-risk applications. Read each row as a trade-off between shorter exposure after theft and the number of sign-in prompts and logouts users experience.

SettingWhat it controlsHigh-risk applicationsStandard and low-risk applicationsLogout and user experience trade-off
Access token lifespanHow long a issued access token is accepted by resource servers without a new request to KeycloakKeep short, typically minutes, so a stolen token expires quickly; confirm the resource servers check expiryModerate, so clients refresh quietly without frequent sign-insShort lifespans cause more refresh calls but rarely prompt users; resource servers must handle refresh correctly
SSO session idleHow long a user's realm session stays valid after the last activity before another login is requiredShort idle timeout so an unattended browser stops granting single sign-onLonger idle timeout to reduce repeated sign-in across connected appsShort values force re-login after breaks and can interrupt long form entry
SSO session maxThe absolute limit on a realm session regardless of activitySet a hard cap so every session ends and a fresh login is forced on a scheduleLonger cap aligned with a working day or policyUsers see a login prompt at the cap even while active, which can surprise them during long tasks
Client session idle and maxThe same idle and absolute limits applied per client session within the SSO sessionTighten for sensitive applications so access ends even when other apps stay activeInherit realm values unless the application needs a different patternPer-client limits can end one app while others keep working, so test logout across the set
Offline session max and idleHow long offline tokens remain usable for background access when the user is not presentDisable or keep minimal, and revoke when staff leave or roles changeUse only for background jobs that need it, with a documented ownerUsers rarely see this, but orphaned offline sessions persist after logout unless revoked
Remember meWhether the login form extends the SSO session across browser restartsTurn off so sessions end with the browser or the session limitsAcceptable on shared-risk internal apps with the realm limits still appliedUsers save retyping credentials, but shared or managed devices carry more exposure
Client-level overridesLifetime values set on an individual client that differ from realm defaultsUse only with a written reason, and review them during client policy auditsUse for legitimate needs such as a long-running batch clientOverrides hide behavior from users and admins, so document each one and confirm logout still reaches the client

Setting lifetimes for high-risk, standard and low-risk applications

Administrative consoles, payment initiation, finance approvals and systems holding regulated personal data carry the largest cost when a session or token is misused. The lifetime posture here favors short access tokens, short idle timeouts and a maximum session age that forces periodic re-authentication, even for users who are active all day. Users are expected to re-enter credentials or a second factor more often, and that trade-off should be agreed with the business owner before the settings are applied.

  • Short access tokens: Keep access token lifespans brief so a leaked token has a narrow window of use, and let the client refresh silently while the SSO session is still valid.
  • Tight idle and maximum timeouts: Set the SSO session idle timeout and SSO session max to values the risk owner signs off, and treat the maximum as the hard stop that idle activity cannot extend.
  • Remember me disabled: Turn off remember me for these realms or clients so that a shared workstation does not keep a session alive across restarts.
  • Offline tokens avoided or tightly scoped: Do not grant offline access unless a documented batch job needs it, and limit it to named clients and a narrow set of roles.
  • Logout tested end to end: Confirm that single logout reaches every client that holds a session, because short lifetimes do not help if a closed browser tab keeps working elsewhere.

Before going live, check each setting against your written access policy and confirm the user experience with the people who will sign in every day.

How to configure and verify session lifetimes in a Keycloak realm

This sequence turns session and token lifetime decisions into a documented, tested configuration for each application, so the realm defaults, client overrides and logout behavior match the risk each application carries.

  1. Inventory applications and classify their risk

    List every client that signs users in to the realm, including web apps, single-page apps, mobile apps, APIs and service accounts. For each one, record who uses it, what data or actions it exposes, whether it is confidential or public, and how sensitive a stolen token would be. Assign each client a risk tier, such as low, standard or high, and note the owner who approves the tier. The output is a reviewed table that maps every client to a tier and an owner, which becomes the basis for every later lifetime decision.

  2. Set realm-level SSO and token defaults

    In the realm settings under Sessions and Tokens, set the SSO Session Idle and SSO Session Max values, the access token lifespan and the client session values to the baseline that fits the most common risk tier. Use the same settings to decide whether remember me is enabled for the realm. Record each value with the reason behind it. Confirm the saved values in the admin console and in the realm export, because the export is what reviewers and change control will read later.

  3. Add client-level overrides for higher and lower risk

    For clients that differ from the realm baseline, set overrides in each client's Advanced settings, such as the access token lifespan and the client session idle and max values. Keep high-risk clients on short access token lifetimes and short idle timeouts. Only lengthen values for clients whose tier and owner justify it. Check that each override appears in the client export, and list any client that still inherits the realm value so the inheritance is intentional.

  4. Decide on remember me and offline access per client

    Decide whether remember me applies to each realm and client, and whether any client needs offline access. Offline tokens can outlive the SSO session, so restrict offline access to clients with a documented need and note who can request it. Write the decision for each client in the inventory. Verify the result by signing in with remember me enabled and disabled, then confirming in the user's session list that the session lifetime matches the decision.

  5. Test token expiry claims and idle behavior

    For each application, obtain a token and decode it to confirm the exp and iat claims match the configured access token lifespan. Then leave the session idle past the configured idle timeout and attempt a request. Record whether the application silently refreshes, redirects to sign-in, or shows an error. This check shows whether the timeouts affect the user as intended and whether the application handles expiry correctly.

  6. Test refresh and logout behavior with each application

    Exercise refresh token use in each application, including a forced refresh after the access token expires. Then test single logout from one application and confirm the session ends in the others that share the SSO session. Check that the application clears its own local session and that a refresh attempt after logout fails. Record each result against the expected behavior. Any application that keeps working after logout or loses its session unexpectedly needs a configuration fix or an application change before sign-off.

  7. Record and approve the verified settings

    Write down the final values for every realm and client setting, the tier and owner for each client, the remember me and offline decisions, and the test results with dates and the Keycloak version used. Export the realm configuration after the change and store it under change control. Ask the security owner to approve the record. The finished record is the evidence an internal audit or a later review will ask for, and it gives the next upgrade a baseline to compare against.

How a login, token refresh and timeout flow through Keycloak

The flow starts when a user signs in to an application and Keycloak creates an SSO session for the browser. The application receives an access token and a refresh token, and it can renew the access token while the SSO session remains valid. When the idle or maximum session timeout ends the SSO session, refresh requests stop succeeding, so the application must send the user back to sign in. Offline tokens sit outside this path, which is why each timeout needs checking against the application's risk.

Sign-in, token refresh and session expiry across the browser, application and Keycloak.

What shorter lifetimes change for logout and users

Shorter token and session lifetimes tighten the window a stolen credential stays useful, but they change how often users sign in and how reliably applications stay signed in. The cards below cover the trade-offs to test before you change a realm or client setting, since each one lands on a different team.

Single logout reach across clients

Shorter SSO session lifetimes end the central session sooner, so users who return to a second application may be asked to sign in again even if they never logged out. Logout reach depends on which clients receive front-channel or back-channel logout notices. Test a sign-out from one application and confirm that every other client in the same SSO session behaves as the security team expects.

Keycloak docs

Re-authentication frequency and prompts

Each reduction in SSO session idle or maximum timeout increases how often users see a login screen, and every extra prompt is a chance for abandoned work. Teams often notice this first in long forms, multi-step approvals and tools used all day. Ask the business owner of each application how long a user can be idle before losing work, then test the prompt on the real login flow, including any MFA step that follows it.

Background refresh failures in SPAs and mobile apps

Single-page and mobile apps renew access tokens in the background with refresh tokens, and a refresh that fails after a session expires shows up as a sudden sign-out or a blank screen. Short lifetimes make these failures more frequent, and some apps retry silently while others do not. Test a session that expires while the app is in the background, a laptop that sleeps overnight and a device that goes offline, then confirm the app recovers without losing unsaved data.

Backchannel logout and token revocation interplay

Backchannel logout asks clients to end their sessions when a central session ends, but it only works if each client registers a logout endpoint and handles the logout token correctly. Shorter lifetimes mean revocation matters less for expiry but more for stolen tokens that remain valid until they expire. Confirm which clients receive backchannel logout notices, how long each client takes to act on them, and whether a revoked refresh token stops access before the access token expires.

Support load from unexpected sign-outs

Unexpected sign-outs generate tickets that look like application bugs, and support staff rarely know that a lifetime setting changed. Keep a record of each lifetime change with its date, the affected clients and the reason, so the help desk can match a spike in tickets to a configuration change. Run a pilot with a small user group, track the number of forced sign-ins and the reasons users report, and agree the response runbook before the change reaches all users.

Questions teams ask before changing Keycloak session lifetimes

What does changing Keycloak session lifetimes cost, and who does the work?

The cost is mostly labor: someone must map each application's risk, change realm and client settings, test sign-in and logout, and document the result. Your internal team pays its own staff time, while a partner is paid for the scope agreed in writing before work starts. The settings themselves cost nothing to change, so the price follows the number of applications, the number of realms, and how much testing and evidence you need. Ask any quote to list the applications covered, the test cases per application, who runs the change windows, and whether the review includes a written record for auditors. Changes are one-time, but reviewing lifetimes again after new applications or policy updates is recurring.

How long does a realm session lifetime review take?

The duration depends mainly on how many applications share the realm, how many use different client types, and how much regression testing each one needs. A realm with a few confidential web apps and one single-page app is far quicker to review than a realm serving dozens of clients with mobile sign-in and API access. Testing time usually dominates, because each application must be checked for silent renewal, forced re-login, and logout behavior. Ask for the review schedule to be tied to a named list of applications, so the timeline reflects what is actually in scope rather than a generic estimate.

What does the work need from our team?

The work needs three things from your side: application owners who can state how each app handles expired sessions and refresh tokens, test accounts with the roles each app uses, and change windows agreed in advance. Application owners matter most, because a lifetime that suits a banking portal can break a long-running internal tool that expects to stay signed in. Test accounts should cover normal users, administrators, and any users who sign in through an identity provider. Change windows let you lower timeouts or revoke sessions without surprising users. Confirm these owners and windows before the scope is signed.

Can an internal team change Keycloak session lifetimes alone?

Yes, an internal team with Keycloak administration experience can change the settings directly in the admin console or through configuration as code. The harder part is knowing what each application does with tokens, which requires developers and product owners to test their own flows. A small internal team often handles one or two realms well but struggles to review many clients at once, because it must also keep up with releases and day-to-day operations. Decide whether the review is a one-time exercise or an ongoing responsibility, and staff it accordingly before you start.

How do session lifetimes relate to offline tokens?

Offline tokens are long-lived refresh tokens that stay valid after the user's SSO session ends, so they are not governed by the same idle and maximum timeouts as a normal session. Offline session settings have their own idle and maximum values, and a shortened SSO session will not shorten an offline session. Applications that request the offline_access scope keep working for as long as their offline token remains valid, which makes them a significant risk if a token is stolen. Review which clients request offline access, set their offline limits deliberately, and confirm that revocation procedures cover them. The Keycloak server administration guide describes each session type, and the review should confirm the behavior in your Keycloak version.

What should we expect for ongoing review of token lifetimes?

Expect a recurring review whenever you add or change an application, change its client type, or alter your risk or compliance requirements. Lifetimes are not a set-and-forget setting, because a new mobile app, API consumer, or identity provider can behave differently from the apps you tested. Keep a register of each realm and client with its access token, SSO session, client session, and offline settings, plus the reason for each value. Upgrades can also change defaults or behavior, so check the release notes before each one. Ongoing support can be handled internally or through a retainer, and the scope of that retainer should name which reviews it includes.

How DeployOpen scopes and delivers session lifetime work

DeployOpen agrees the scope of session lifetime work in writing before any settings change. The first step is classifying each application that signs in through the Keycloak realm by risk: how sensitive the data is, whether the client is a confidential server-side app, a single-page app or a mobile app, how long users typically work in it, and whether it holds offline access. The written scope then lists the realm and client settings expected to change for each class, such as access token lifespan, SSO session idle and maximum timeouts, client session limits, offline session behavior and the remember me option. It also names the environments covered, the change approach for each realm, and who on the client side approves the new values.

The scope also defines the test cases and the evidence. Test cases cover refresh behavior at the point a token expires, what a user sees when an SSO session times out during an open application, whether logout from one application ends sessions in the others, and how each client responds after an idle timeout. DeployOpen delivers the configuration as it was found and as it was changed, the test results with the steps used to reproduce them, the documented decisions per application class, and a list of follow-up items for your team. Compliance assessments are the client's responsibility to schedule with an independent auditor. DeployOpen prepares the configuration records and test evidence that such an assessment may request, but it does not issue audit reports or certifications.

Session policy drifts as applications are added and as teams change timeout values to fix user complaints, so ongoing review is often the more useful service after the first change. DeployOpen offers that review as a retainer, covering periodic checks of the classification against new applications and a rerun of the refresh and logout test cases after Keycloak upgrades. Ask any partner, DeployOpen included, to show the written scope, the test list and the evidence format before work starts, and confirm which environments and which Keycloak release line the scope covers.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.