Keycloak single logout for OIDC and SAML applications

Single logout in Keycloak ends the session across applications only when each application implements the logout method it supports. This page explains the OIDC and SAML options, what each requires, and how short token lifespans limit exposure when logout cannot reach an app.

On this page

Why Keycloak single logout needs planning per application

Single logout is an application-level commitment as well as a Keycloak setting, because a user's sign-out only ends their sessions everywhere if each application acts on the signal it receives. When several apps share one realm, signing out of one can leave an active session in another. Keycloak describes four OpenID Connect specifications relevant to logout: Session Management, RP-Initiated Logout, Front-Channel Logout and Back-Channel Logout. Each one places different work on the application, so the choice is made app by app. Realm and client settings decide what Keycloak sends, but each application's session handling decides whether it ends its own session.

Teams usually need coordinated logout when users move between related business systems on shared or sensitive devices, or when one app exposes data that should not stay reachable after sign-out. A simpler approach can be enough for a single application, for a set of apps that users rarely switch between, or where a short session lifetime is an accepted control. For example, in an illustrative setup, a user signs out of an HR portal but can still open a finance tool without a new prompt until its session expires. Confirm with the business owners which apps must end together before you choose a method.

Plan logout as an inventory exercise. For each application, record its protocol (OIDC or SAML), whether it keeps a browser session, a server-side session or a mobile session, and whether it can receive logout requests from Keycloak at a reachable endpoint. Ask each application team how it handles logout callbacks and what happens if a callback never arrives. Where logout cannot reach an application, the access token lifespan sets how long that application keeps accepting a token after sign-out, so confirm those values with the owners. The Keycloak server administration guide is the reference for the settings you will need to verify per client.

How OIDC and SAML logout methods differ

RP-initiated logout is triggered by the application itself. When a user chooses sign-out in the app, the relying party (RP) redirects the browser to the Keycloak end session endpoint, which is defined by the OIDC RP-Initiated Logout specification that Keycloak describes in its administration guide. This ends the user's session at Keycloak, and the user can then be sent back to the application. The application's responsibility is to start this redirect, not just clear its own local cookie or session.

  • Trigger: a user action in the application, such as a sign-out button, starts the redirect.
  • Application must expose: a sign-out route that builds the end session request and clears the local session.
  • Redirect target: a post-logout redirect URI must be registered in the client settings, or Keycloak will not return the user to the app.
  • Hint for the request: the ID token hint is passed so Keycloak can identify the session to end.
  • Failure point: if the app only clears its own cookie, the Keycloak session stays alive and the next sign-in happens without a password prompt.

Check that every sign-out path in the application, including session timeouts, calls the same route, and that post-logout redirect URIs match the client configuration exactly.

Which logout option fits which application

This table compares the four logout mechanisms Keycloak supports for OIDC and SAML applications, plus the non-standard direct endpoint call, against what each needs from the application and whether Keycloak must reach it. Read each row against the application's architecture to find the option that fits, then check the reachability column before committing. The main takeaway is that only some options can end sessions in apps that browsers cannot reach, which is why token lifespan matters for the rest.

Logout optionWhat the application must provideMust Keycloak reach the app?When it fits
OIDC RP-initiated logoutA way to send the user's browser to Keycloak's end session endpoint, with a registered post logout redirect URINo, the browser carries the requestEnding the Keycloak session from a link or button in the app's own UI
OIDC front-channel logoutA logout URI in the client settings that loads inside the browser and clears the app's local sessionNot server-to-server, but the browser must load the app's logout pageBrowser-based apps where the user's browser can load the app in a hidden frame
OIDC back-channel logoutA server endpoint that accepts a signed logout token from Keycloak and ends the matching sessionYes, Keycloak sends a request directly to the app's serverServer-side apps and APIs that must end sessions even when the browser is closed
SAML single logoutSupport for SAML logout requests and responses on its service provider endpointsKeycloak sends logout messages to the app's SLO endpoint, usually through the browserExisting SAML service providers that already implement single logout
Direct logout endpoint call with refresh token and client credentialsThe application holds a refresh token and client secret and calls the logout endpoint itselfNoNot recommended by Keycloak's OIDC guide because it is non-standard; use RP-initiated or back-channel logout instead

How a logout request moves through Keycloak and each application

The diagram starts when a user selects sign-out in one application. That application sends an RP-initiated logout request to Keycloak, which ends the SSO session and then notifies every other relying party that held a session. Front-channel notifications travel through the user's browser, while back-channel notifications go server to server to each application's logout endpoint. The branch shows an application that cannot be reached, where its access token stays valid until it expires, so token lifespan sets the exposure window. Check each application's logout endpoint and token lifetime before relying on the flow.

Logout ends the Keycloak session and notifies each relying party, with an unreachable application as the failure branch.

How to configure single logout in Keycloak step by step

This sequence takes a Keycloak realm from a planned logout design to a tested state where ending a session in one place signs the user out of every connected application that supports the chosen logout method. Each step closes with a check you can run before moving on.

  1. Inventory realm, clients and logout requirements

    Start by listing every application that signs in against the realm, and record whether each is an OIDC client or a SAML client, whether it is public or confidential, and whether it runs in the browser, on a server or on a device. Note which applications must end their local session when a user logs out elsewhere, and which can only be signed out by their own session timeout. Confirm your realm layout with the team that owns each application. This step is done when you have one table that maps each client to a protocol, a client type and a logout method. Owner: the Keycloak administrator with each application owner.

  2. Set valid post-logout redirect URIs per client

    For each OIDC client, open its settings in the admin console and set the valid post-logout redirect URIs to the exact return addresses the application uses after sign-out. Keep the list short and avoid wildcards that match more than the application needs. For SAML clients, confirm the single logout service URLs and the binding each application expects. Check the result by calling the RP-initiated logout endpoint from a test browser with an id_token_hint and a post_logout_redirect_uri that is on the list, then confirm Keycloak redirects to it. Repeat with an unlisted URI and confirm Keycloak does not redirect there.

  3. Configure front-channel logout where it is supported

    Where an application uses a browser-based front-channel logout URL, enter that URL in the client's logout settings in the admin console. Front-channel logout works by loading the application's logout pages in the user's browser, so it depends on the browser allowing those requests and on the application accepting them. Note that browser privacy settings and third-party cookie blocking can prevent it from completing. Confirm the setting saved by reopening the client. The check for this step is a test login to two applications that both list front-channel URLs, then a logout from one, and a note of whether the second application's session ends without further action.

  4. Enable back-channel logout endpoints in each client

    For applications that can receive server-to-server calls, set the back-channel logout URL on the client and choose whether the session identifier must be sent with the logout token. Confirm the application's endpoint accepts a signed logout token and ends the matching local session. Keycloak documents a mandatory signature check on back-channel logout tokens from external identity providers in the 26.8 upgrade notes, so make sure any broker or external token source is configured with valid keys before you rely on it. The check for this step is a logout from a test user's session in the admin console and a log entry in the application showing it received and accepted the logout token.

  5. Configure SAML single logout for SAML clients

    For each SAML client, confirm the single logout service URL and binding that the service provider publishes, and make sure the signing certificate in Keycloak matches the one the application trusts. Test a SAML logout from the application side and from the Keycloak side. Keep in mind that SAML single logout depends on each service provider implementing its own logout handler correctly, so verify the behavior with the application's documentation rather than assuming it. The check is that a logout initiated in one SAML application produces a logout request that reaches Keycloak and clears the user's session, which you can see in the admin console session list.

  6. Set token lifespans for applications that cannot receive logout

    Some applications, especially single-page apps without a backend and older clients, cannot receive any logout signal. For these, reduce the access token lifespan and the SSO session idle and maximum settings to values your security policy supports, so a stale token stops working soon after the user signs out. Record the values you set and the applications they affect. Confirm the setting in the realm's token and session settings, then verify by signing in, logging out elsewhere, and attempting a call to the affected application's API after the access token expires. Shorter lifespans increase refresh traffic to Keycloak, so measure that load before going further.

  7. Test logout across applications and record results

    Run an end-to-end test with at least two applications from each protocol. Sign in to all of them, log out from one, and check that each other application ends its session or prompts for a new login on the next request. Use the admin console to confirm the user's sessions are removed for the realm. Record each result in a matrix with the client, method, expected outcome and observed outcome. Repeat the test after any client change and after a Keycloak upgrade. The step is complete when every row in the matrix matches its expected outcome, or when each gap is documented with a planned mitigation, such as a reduced token lifespan or an application owner's fix.

  8. Document the logout design and confirm ownership

    Write down the logout method chosen for each client, the post-logout redirect URIs, the back-channel and front-channel URLs, the token lifespans, and the known gaps from the test matrix. Assign an owner for each application's logout behavior so that changes in the application are reviewed against the Keycloak settings. Review the document with the security team and the application owners. The step is complete when each client has a named owner, each known gap has an accepted risk or a fix date agreed with its owner, and the matrix is stored with the realm configuration.

What each application must implement for logout to work

Keycloak can end its own session and notify registered clients, but each application must still accept those signals and clear its own session. The cards below separate the application build from the Keycloak client settings, so teams can assign ownership before testing starts.

Registered logout redirect URIs

Every OIDC client needs its post-logout redirect URIs registered in Keycloak before RP-initiated logout can send a user back to the application. Each URI should be an exact match for a page the app serves, such as a signed-out landing page. Check that wildcards are avoided and that each environment (development, test, production) has its own entry. A missing entry usually shows up as an error page at sign-out rather than as a failed login.

Keycloak docs

Back-channel logout endpoint

The application must expose an endpoint that Keycloak calls server to server with a logout token when a session ends. The handler must validate the token signature, issuer, audience and the events claim before acting on it. It should then find the local sessions tied to the sid or subject in the token. Treat any token that fails validation as untrusted and do not clear sessions on its basis.

Session invalidation in the app's store

Receiving a logout signal is not enough on its own. The application must delete or revoke its own session records, including server-side sessions, cached tokens and any remember-me cookies it issues. Confirm that the app keys its sessions to the Keycloak sid claim so that back-channel logout can find them. Test that a second browser or device signed in to the same app is also logged out.

SAML logout request handling

A SAML service provider must accept logout requests from the Keycloak identity provider and respond with a logout response that Keycloak can process. The app must verify the signature on the request, match the NameID and session index to a local session, and then end that session. Confirm the single logout service URL and bindings in both the SP metadata and the Keycloak client, since a mismatch often fails silently.

Front-channel logout and cookie settings

For front-channel logout, Keycloak loads a hidden logout URL in the user's browser for each client, which only works when the browser sends the app's cookies in that request. The application must set its session cookies with suitable SameSite and Secure attributes and must serve the logout page over HTTPS. Browsers that block third-party cookies can break this path, so back-channel logout is the more reliable choice for apps that need guaranteed session ends.

Logout test cases owned by the app team

The application team should write tests that prove each path works: a user logs out of one app and is signed out of the others, a revoked session cannot call the API, and a replayed logout token is rejected. Record the expected result for each Keycloak client type you use. Ask the vendor or your own engineers to confirm how the framework library in use handles each logout standard before you rely on it.

Why short access token lifespans matter when logout cannot reach an app

An application that never receives a logout signal keeps honoring the access tokens it already holds until they expire. Single logout can end the Keycloak session and notify applications that registered back-channel or front-channel logout endpoints, but an app that is offline, uses a client without a logout URL, or ignores the notification has no way to learn that the user has left. For that app, the access token lifespan set on the realm or client is the size of the window in which a stolen or still-cached token keeps working. Before go-live, ask each application owner whether it implements logout callbacks, and record the access token lifespan that applies to each client. Confirm those values in your own Keycloak admin console rather than relying on defaults you have not reviewed.

Shortening access tokens narrows that window but has a cost. Each expiry forces the client to obtain a new token, and when the client uses a refresh token, Keycloak must process more token requests and the sessions behind them. Refresh token lifespans and whether refresh tokens rotate also determine how long a session survives without user activity, so a short access token paired with a long refresh token does not by itself end access. Load testing with your expected concurrent users is the practical way to size this, and the Keycloak high availability guidance is the right place to plan capacity once the lifespans are settled. Also confirm with your applications how they handle token refresh failures, because a poorly written client can turn short lifespans into user-visible sign-in loops.

How an API checks tokens also determines how quickly a logout or revocation takes effect. An API that validates signatures locally against realm keys will accept a token until its expiry, regardless of what happened in Keycloak, whereas an API that calls token introspection can see that a session is no longer active, at the cost of a request to Keycloak on each check. The choice between these approaches is covered in the token validation topic, but it belongs in this logout design: if your APIs validate locally, the access token lifespan is your only bound on post-logout access. Document the validation method for every protected API and treat the lifespan as a security control that needs an owner, a review date and a test.

Security and operational risks of single logout

Single logout only works when every relay party cooperates, and the failure modes are quiet: a missed back-channel token, a loose redirect target or an app that never ends its own session. The cards below cover the risks that show up most in Keycloak logout designs and the checks that catch them before users or auditors do.

Validate external logout tokens

Back-channel logout sends a signed logout token to each client. Keycloak 26.8 makes signature validation of backchannel logout tokens from external providers mandatory, so an identity broker setup that relied on unsigned or unchecked logout messages will change behavior after the upgrade. Confirm which upstream providers send back-channel logout, test that signed tokens are accepted, and reject any token that fails validation rather than logging the user out on an unverified message.

Upgrading guide

Restrict post-logout redirect URIs

RP-initiated logout can send the user back to a URI after the session ends. If the registered post-logout redirect URIs are wildcards or broad patterns, an attacker can craft a logout link that bounces users to a hostile site, which is an open redirect. Register exact URIs for each client, keep them on hosts you control, and review them whenever a client adds a new environment or domain.

Sessions that outlive logout

Logout only ends the session that Keycloak can reach. A single-page app that keeps tokens in memory, a mobile app that holds a refresh token, or a legacy app with its own cookie can stay signed in after the user has logged out of Keycloak. Inventory each application, record whether it implements front-channel, back-channel or no logout, and document the residual risk for the apps that cannot be reached.

Short access token lifespans

When logout cannot reach an application, the access token it holds is the remaining window of exposure. Shorter access token lifespans limit how long a stolen or orphaned token stays usable, and they force refresh requests that Keycloak can deny after logout. Set the lifespan from your own risk tolerance and test how each client behaves when refresh fails, since a poor retry loop can make the app look broken.

Log and measure logout events

Logout failures rarely raise errors anywhere a user will see them. Start Keycloak with --metrics-enabled=true to expose Prometheus-format metrics at /metrics on the management interface, and enable the optional HTTP request and cache histograms when you need latency detail. Pair those metrics with server logs for logout requests so that a rise in failed back-channel deliveries or unexpected session counts is visible to the operations team.

Metrics guide

Retest logout after every upgrade

Logout behavior depends on client settings, provider configuration and validation rules, and any of them can change in a release. Keycloak plans four minor releases a year, and the 26.8 notes changed how logout tokens are validated. Keep a written logout test script covering each client type, both logout flows and a broker login, and run it on a staging realm before each upgrade and before changing client logout URIs.

Questions teams ask before implementing Keycloak single logout

What does Keycloak single logout cost to implement, and what drives the effort?

The cost is mostly the time of the people who change applications and test them, plus the Keycloak configuration work, and it is largely one-time. The main drivers are the number of applications, the protocol each one uses (OIDC or SAML), the client library or framework each app runs on, and whether sessions are held in a custom store that must be cleared on logout. An app that already has a maintained OIDC library with logout support is much less work than a legacy app that manages its own cookies. Ask any partner for a quote that lists each application, its protocol and library, its logout behavior, and the test environments it needs. Recurring cost appears when those apps change and logout has to be retested after each change.

How long does Keycloak single logout take with many applications?

Duration grows with the number of applications and the variety of their logout methods, so the honest answer depends on your inventory. DeployOpen does not publish timelines. Work usually runs in phases: first, a Keycloak client setting review and a sample app proving the logout path; then the remaining applications in batches; then end-to-end testing across the whole set. An application that needs a code change in its own session handling will take longer than one where the change is a client setting. Ask for a schedule tied to the agreed scope, and confirm which applications your developers must own, since their availability often sets the pace more than Keycloak configuration does.

What does the team need from app developers and Keycloak administrators?

Single logout touches two groups that rarely work together day to day. Application developers must implement or confirm the logout endpoint, front-channel or back-channel handling, and session cleanup in each app. Keycloak administrators must set the logout redirect URIs, the back-channel logout URL and session settings on each client, and manage the realm they run. You also need test environments that mirror production hostnames, because logout redirects and cookies fail on mismatched URLs. Agree on one owner per application and one owner for the Keycloak realm before work starts, so a missing redirect URI does not stall a release.

Can our internal team implement Keycloak single logout alone?

An internal team can do it if it has developers who know each application's session handling and administrators comfortable with Keycloak client settings. The gap usually appears in cross-application testing and in legacy apps that nobody currently maintains. Keycloak's OIDC guidance says invoking the logout endpoint directly with a refresh token and client credentials is non-standard and not recommended for applications, so a team that copies a shortcut from an old example can create a fragile setup. A fixed-scope engagement with DeployOpen covers the agreed applications, configuration and written test results, while your team keeps ownership of the applications. Compare that against the time your own engineers would spend on the same work.

How do we test Keycloak single logout end to end?

Test from the user's side: sign in to several applications in one browser, sign out in one of them, then confirm each other application requires a new login and that no session cookie or local token survives. Repeat with each protocol mix you run, including OIDC RP-initiated logout, back-channel logout and SAML single logout where used. Include a failure case, such as a back-channel call that cannot reach an application, and check what the user sees and how long the old session stays valid. Record the results per application and retest after every upgrade or client change. Keep the test accounts and environments documented so the test can be rerun later by someone else.

What changes after a Keycloak upgrade, and does logout need retesting?

Yes, retest logout after every Keycloak upgrade, because the server and its client handling can change between releases. The Keycloak 26.8 upgrade notes, for example, make signature validation of backchannel logout tokens from external providers mandatory, so an external identity provider that previously passed without validation may now need its keys configured. Read the upgrade notes for each version between your current and target release, and check the Keycloak upgrading guide before you start. Also confirm that the Keycloak Operator, if you use it, is set to manual approval so an upgrade does not happen unplanned. Keep the logout test suite from the initial build so the same checks run before and after each upgrade.

Where to read the Keycloak logout specifications

Start with the Keycloak server administration guide, because it is the authoritative description of how this Keycloak release handles logout. It names the four OIDC specifications that matter for logout: Session Management, RP-Initiated Logout, Front-Channel Logout and Back-Channel Logout. Read it to decide which of these your applications need, since each one asks something different of the client and of Keycloak's client settings. The same guide covers SAML single logout for SAML clients, so the sections on SAML clients belong in the same review as your OIDC clients. Use the version selector on the documentation before relying on any setting, because logout behavior can change between releases.

The OIDC securing applications guide is the next read for the application side. Its job is to show what your own code must do: where the logout endpoint is called from, how the ID token hint is passed, and which redirect URI the application must register after logout. Keep one decision in front of you while reading it: whether each application can receive a logout call from Keycloak at all. A server-side web app can usually host a back-channel logout endpoint, while a single-page app or mobile app usually cannot. The guide also states that calling the logout endpoint directly with a refresh token and client credentials is non-standard and not recommended, so plan your logout flow around the browser redirect instead.

Confirm the details with your own test environment rather than assuming the documentation matches your deployment. Ask your team to list every client in the realm, mark which ones are public, confidential or SAML, and note which ones have a session that outlives the browser. Then check each client's logout settings against the chapters you have read. The result is a short written list of what each application expects, which becomes the input for the logout design and for any access token lifespan decisions that follow.

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.