fix: keycloak authentication post logout redirect for Keycloak 18+ #5878
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This fixes the Keycloak authentication strategy post logout redirect from Keycloak 18 and above when 'Logout from Keycloak on Logout' is enabled. Additionally, a new parameter has been added to the strategy config to enable the old behavior for legacy versions of Keycloak.
This was brought up in discussion #5213 and partially addressed in unmerged #5513. That PR fixes the logout error in Keycloak 18+, but doesn't provide a redirect back to the wiki.
Why?
In older versions of Keycloak, the 'redirect_uri' parameter can be passed to the logout endpoint to automatically log out and redirect afterwards. Starting with Keycloak 18, this has been replaced with 'post_logout_redirect_uri'. This parameter must be accompanied by 'id_token_hint' with its value set to the id_token obtained at login.
How?
The id_token from Keycloak is saved to the user's session upon successful authentication and added as 'id_token_hint' when generating the post logout redirect. Enabling 'Legacy Logout Redirect' in the strategy config will revert to the old behavior of using only 'redirect_uri'.