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.
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=Zq3v8sample7KpW2If 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
| Parameter | Meaning |
|---|---|
id_token_hint | An 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_uri | Where to send the user afterwards. It must be registered on the client in advance. |
client_id | The client’s id. Useful when you have no ID token, so the provider knows whose registered URIs to check. |
state | A value returned to you on the redirect, to tie it to your request. |
ui_locales | Preferred languages for any page the provider shows. |
logout_hint | A 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,stateandui_locales, leaving out empty ones. - It makes a random
statein 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
- Enter your Keycloak server URL and realm, or switch to Custom URL and paste the
end_session_endpointfrom the discovery document. - Paste the ID token your app received at sign-in into
id_token_hint. - Enter the page the user should land on, exactly as it is registered on the client.
- Keep
client_idfilled in. Addui_localesif you want the provider’s pages in a given language. - 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
statewhen the user comes back, as you would for sign-in. - The ID token in
id_token_hinttravels 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_hintandclient_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.