Skip to content

Keycloak logout URL builder

Build an OpenID Connect RP-initiated logout URL with id_token_hint, post_logout_redirect_uri, client_id and state.

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

Logout request

The base URL, without /realms/…. Add a path if your server has one, such as /auth on old versions.

The ID token from the user’s sign-in. Stays in your browser.

Where to send the user after logout. Must be registered on the client.

Tells the server which client’s registered URIs to check.

Logout URL

URL
https://auth.example.com/realms/acme/protocol/openid-connect/logout?post_logout_redirect_uri=https%3A%2F%2Fapp.example.com%2F&client_id=web-app
Without id_token_hint
Keycloak asks the user to confirm the logout, because it cannot be sure the request came from the app. Send the ID token to log out without that page.
post_logout_redirect_uri
https://app.example.com/
client_id
web-app
Keycloak notes
Keycloak 18 and later expect post_logout_redirect_uri; older guides use redirect_uri. The URI must match the client’s Valid post logout redirect URIs, where + means the same list as Valid redirect URIs.
This ends the session at Keycloak. Clear your app’s own session too, before or after the redirect.

How to use it

  1. Enter your Keycloak server URL and realm, or a custom end session endpoint.
  2. Paste the user’s ID token as id_token_hint.
  3. Enter where the user should land afterwards, registered on the client.
  4. Copy the URL and send the browser to it.

What to know

RP-initiated logout sends the browser to the provider’s end session endpoint, which ends the session there and can send the user back. In Keycloak it is https://<host>/realms/<realm>/protocol/openid-connect/logout.

Keycloak 18 and later expect post_logout_redirect_uri, with id_token_hint or client_id. Older guides use redirect_uri, which no longer works by default.

Without id_token_hint, Keycloak asks the user to confirm the logout. post_logout_redirect_uri must match the client’s Valid post logout redirect URIs, where + means the same list as Valid redirect URIs.

What RP-initiated logout is

Signing out of an app that uses OpenID Connect has two parts. Your app ends its own session, and the identity provider ends the single sign-on session it keeps for the user. If you only do the first part, the next sign-in happens silently, because the provider still remembers the user.

RP-initiated logout is the standard way to do the second part. The app, called the relying party, sends the browser to the provider’s end session endpoint. The provider ends the session and, if asked, sends the user back to a page of your choice. It is defined in the OpenID Connect RP-Initiated Logout 1.0 specification.

How the logout request works

The logout request is a browser redirect, usually a GET with query parameters. The specification also allows a form POST with the same parameters.

Sample logout URL (made-up values, line breaks added for reading)
https://auth.example.com/realms/acme/protocol/openid-connect/logout
  ?id_token_hint=SAMPLE_ID_TOKEN
  &post_logout_redirect_uri=https%3A%2F%2Fapp.example.com%2F
  &client_id=web-app
  &state=Zq3v8sample7KpW2

If the provider accepts the request, it ends the session and redirects the browser to post_logout_redirect_uri, adding state if you sent one. Your app checks that state matches the value it stored before the redirect.

The parameters

ParameterMeaning
id_token_hintAn ID token the provider issued to this user. Recommended. It tells the provider which session and which client the request is about.
post_logout_redirect_uriWhere to send the user afterwards. It must be registered on the client in advance.
client_idThe client’s id. Useful when you have no ID token, so the provider knows whose registered URIs to check.
stateA value returned to you on the redirect, to tie it to your request.
ui_localesPreferred languages for any page the provider shows.
logout_hintA hint about which user to log out, when there is no ID token.

What this tool does

The tool builds the logout URL from the parameters you enter and lists each one. Nothing is sent, and the ID token you paste stays in your browser.

  • It builds Keycloak’s end session endpoint from a server URL and realm, or uses any custom URL.
  • It adds id_token_hint, post_logout_redirect_uri, client_id, state and ui_locales, leaving out empty ones.
  • It makes a random state in your browser, and a new one on request.
  • It warns when Keycloak would reject the request or ask the user to confirm.

It does not open the URL, end any session, or clear your app’s own session. It also does not check whether your redirect URI is registered; the redirect URI matcher helps with the matching rules for sign-in redirects.

How to use the tool

  1. Enter your Keycloak server URL and realm, or switch to Custom URL and paste the end_session_endpoint from the discovery document.
  2. Paste the ID token your app received at sign-in into id_token_hint.
  3. Enter the page the user should land on, exactly as it is registered on the client.
  4. Keep client_id filled in. Add ui_locales if you want the provider’s pages in a given language.
  5. Copy the URL. In your app, store state, clear your own session, and redirect the browser to the URL.

Logout in Keycloak

Keycloak’s end session endpoint is https://<host>/realms/<realm>/protocol/openid-connect/logout. The discovery document lists it as end_session_endpoint.

What changed in Keycloak 18

Keycloak 18 and later follow the RP-Initiated Logout specification. They expect post_logout_redirect_uri, together with id_token_hint or client_id. Many older guides and libraries send redirect_uri instead, which no longer works by default. If logout stopped redirecting after an upgrade, this is the usual reason.

The confirmation page

Without id_token_hint, Keycloak cannot be sure the request came from your app, so it asks the user to confirm the logout. Send the ID token to log the user out without that page.

Valid post logout redirect URIs

Each client has a Valid post logout redirect URIs setting. post_logout_redirect_uri must match one of its entries. The value + means the same list as Valid redirect URIs, so a client set up for sign-in already accepts those addresses for logout.

Other clients in the same session

A Keycloak session can cover several apps. When it ends, Keycloak can tell the other clients, through front-channel logout (the browser loads a page of each app) or back-channel logout (Keycloak calls each app’s server). Both are set per client.

Use cases

Web apps with a back end

The server deletes its session, revokes any offline token it held, and redirects the browser to the logout URL. Keep the ID token on the server for exactly this purpose.

Single-page apps

The app drops the tokens from memory and sends the browser to the logout URL with the ID token as hint. Register the page the user should land on as a valid post logout redirect URI.

Mobile and desktop apps

A native app opens the logout URL in the same system browser it used for sign-in, because that browser holds the provider’s session cookie. Opening it in a different browser would end nothing.

Common errors and how to fix them

An error about the redirect URI

Keycloak shows an error page instead of redirecting. post_logout_redirect_uri is not in the client’s Valid post logout redirect URIs, or the request had neither id_token_hint nor client_id, so Keycloak could not tell which client’s list to check. Register the exact URI and send one of the two.

The user is still signed in afterwards

  • Your app cleared its own session but never redirected to the logout endpoint.
  • The logout URL was called from your server with an HTTP client. The provider’s session lives in the browser’s cookie, so the browser itself must visit the URL.
  • A mobile app opened the logout URL in a different browser from the one used for sign-in.

Logout lands on a Keycloak page instead of your app

No post_logout_redirect_uri was sent, or the confirmation page appeared because id_token_hint was missing. Send both.

Security notes

  • Register exact post logout redirect URIs. An open redirect after logout can send users to a phishing page that looks like your sign-in.
  • Check state when the user comes back, as you would for sign-in.
  • The ID token in id_token_hint travels in the URL, so it can appear in browser history and server logs. It holds personal data, so keep those logs short-lived.
  • Revoke offline tokens on logout if your app holds any. They belong to a separate offline session, so ending the browser session does not stop them.

Best practices

  • Always send id_token_hint and client_id.
  • Clear your own session first, so a failed redirect still leaves the user signed out of your app.
  • Land the user on a page that does not trigger a new sign-in at once.
  • Use back-channel logout for server-side apps that must end their own sessions when another app logs the user out.

If you want Keycloak run for you, with upgrades handled, see pricing; Starter and Premium start with a 7-day trial, card required.

Questions

Frequently asked questions

What is the Keycloak logout URL?

`https://<host>/realms/<realm>/protocol/openid-connect/logout`, with `id_token_hint`, `post_logout_redirect_uri`, `client_id` and optionally `state` as query parameters. The realm’s discovery document lists it as `end_session_endpoint`.

Why does Keycloak show “Do you want to log out?”

The request had no `id_token_hint`, so Keycloak cannot tell that it came from your app. Send the ID token from the user’s sign-in to skip the page.

Why does redirect_uri no longer work for Keycloak logout?

Since Keycloak 18, logout follows the OpenID Connect RP-Initiated Logout specification, which uses `post_logout_redirect_uri`. Send that instead, together with `id_token_hint` or `client_id`.

What does + mean in Valid post logout redirect URIs?

It means “the same list as Valid redirect URIs”. A client that accepts a URI for sign-in then accepts it for logout too.

Can I log a user out of Keycloak from my server?

The RP-initiated logout URL must be opened by the user’s browser, which holds the session cookie. A server-side HTTP call does not end the browser’s session. Admins can end a user’s sessions in the admin console.

Does logging out of Keycloak log the user out of my app?

Not by itself. Your app must clear its own session. To learn when another app ended the session, set up front-channel or back-channel logout on your client.

What is the difference between front-channel and back-channel logout?

With front-channel logout the provider makes the user’s browser load a logout page of each app, so it depends on the browser and its cookie rules. With back-channel logout the provider sends a signed logout token straight to each app’s server, as OpenID Connect Back-Channel Logout 1.0 defines. Back-channel is the more reliable of the two.

Is id_token_hint required?

The specification recommends it rather than requiring it. In Keycloak, a `post_logout_redirect_uri` needs either `id_token_hint` or `client_id`, and without the ID token the user sees a confirmation page.

Should I also revoke tokens when the user logs out?

It is a good habit. In Keycloak, ending the session also stops the refresh tokens tied to it, but offline tokens keep working until revoked. Revoking what you hold is the portable way to be sure, whatever the provider.

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.