Skip to content

[Feature Request] Backchannel sign-out endpoint to invalidate session #1224

Open
@ghuser0

Description

@ghuser0

Hi,

To support single-sign-out for Keycloak, in the Keycloak client registration it is possible to specify a backchannel logout URL. If a user authenticated in a realm signs out using any client, keycloak will call this backchannel logout URL for all clients in the realm.

Example

A user has two apps app1.example.com and app2.example.com using oauth2-proxy to secure access using a single Keycloak realm at keycloak.example.com.

The user first visits app1.example.com. They are redirected to keycloak.example.com to sign in. The user signs in and keycloak sets a session cookie, as well as redirects back to app1.example.com/oauth2/callback with an authorization code. oauth2-proxy on app1.example.com creates a session for the user in redis, and sets the oauth2 client cookie to index the redis session.

The user then visits app2.example.com. They are redirected to keycloak.example.com, where they already have a keycloak session cookie. Keycloak keeps the user signed in and automatically redirects back to app2.example.com/oauth2/callback with an authorization code. oauth2-proxy on app2.example.com creates a session for the user in redis, sets the oauth2 client cookie, and the user is automatically signed in after a bunch of redirects with the magic of oauth SSO.

The user now wants to sign out. The user visits app1.example.com/oauth2/sign_out?rd=https%3A%2F%2Fkeycloak.example.com%2Fauth%2Frealms%2Frealm%2Fprotocol%2Fopenid-connect%2Flogout%3Fredirect_uri%3Dhttps%3A%2F%2Fapp1.example.com%2F. app1's oauth2-proxy clears its session, then redirects to keycloak which clears its session, and then redirects back to app1 which is now logged out.

Expected Behavior

When the keycloak logout endpoint is hit, it should use the backchannel logout url of all of its clients to invalidate their sessions. That is, keycloak.example.com should make a backchannel request to app2.example.com to invalidate the user's session. After logging out of app1.example.com, if the user visits app2.example.com, they should be logged out of app2 as well.

Current Behavior

Without a backchannel logout URL in oauth2-proxy, when the user signs out of app1.example.com, the sessions of app1.example.com and keycloak.example.com are cleared, but app2.example.com isn't touched. As a result, if the user later visits app2.example.com, they continue to be logged in.

Possible Solution

A backchannel logout endpoint, that receives a logout token and clears the associated session in redis. This would only work for redis sessions, not cookie sessions, since a backchannel request can't reach in to the user's user-agent to clear cookies.

Your Environment

oauth2-proxy v7.1.3
Keycloak v13.0.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions