feat(auth): add id_token_hint to OIDC RP-Initiated Logout - #38787
Open
gomitrah wants to merge 2 commits into
Open
feat(auth): add id_token_hint to OIDC RP-Initiated Logout#38787gomitrah wants to merge 2 commits into
gomitrah wants to merge 2 commits into
Conversation
gomitrah
force-pushed
the
feat/38692-oidc-logout-id-token-hint
branch
from
August 5, 2026 09:45
e1256fc to
a516b7c
Compare
gomitrah
force-pushed
the
feat/38692-oidc-logout-id-token-hint
branch
from
August 6, 2026 08:20
a516b7c to
f061ad5
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves OIDC RP-Initiated Logout compatibility by persisting the OIDC id_token in the user session at sign-in time and reusing it as id_token_hint when building the provider end_session_endpoint redirect during logout.
Changes:
- Store
goth.User.IDTokeninto the session (session.KeyOIDCIDToken) during OAuth2/OIDC sign-in (including 2FA and link-account 2FA flows) when present. - Add
id_token_hintto the OIDC end-session URL when the session contains a non-empty stored ID token. - Add/extend unit tests to cover ID token persistence and inclusion/omission of
id_token_hint.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| routers/web/auth/oauth.go | Stores id_token in session on OAuth2/OIDC sign-in and adds id_token_hint to the logout redirect when available. |
| routers/web/auth/linkaccount.go | Stores id_token in session during OAuth2 link-account 2FA session setup. |
| routers/web/auth/auth_test.go | Adds tests asserting session storage of id_token and presence/absence of id_token_hint on logout redirects. |
| modules/session/key.go | Introduces session.KeyOIDCIDToken session key constant and documentation. |
Suppressed comments (1)
routers/web/auth/oauth.go:466
- Same session-regeneration issue as the non-2FA path: if this OAuth2/OIDC callback doesn’t yield an
id_token, the previoussession.KeyOIDCIDTokenvalue can be carried into the regenerated 2FA session and later used as a staleid_token_hint. Clear the key before callingregenerateSession.
sessionData := map[string]any{
"twofaUid": u.ID,
"twofaRemember": false,
session.KeySignInMethod: session.SignInMethodOAuth2,
}
if gothUser.IDToken != "" {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+431
to
+436
| sessionData := map[string]any{ | ||
| session.KeyUID: u.ID, | ||
| session.KeyUserHasTwoFactorAuth: userHasTwoFactorAuth, | ||
| session.KeySignInMethod: session.SignInMethodOAuth2, | ||
| }); err != nil { | ||
| } | ||
| if gothUser.IDToken != "" { |
Comment on lines
+174
to
+180
| sessionData := map[string]any{ | ||
| "twofaUid": u.ID, | ||
| "twofaRemember": remember, | ||
| "linkAccount": true, | ||
| session.KeySignInMethod: session.SignInMethodOAuth2, | ||
| }); err != nil { | ||
| } | ||
| if linkAccountData.GothUser.IDToken != "" { |
gomitrah
force-pushed
the
feat/38692-oidc-logout-id-token-hint
branch
3 times, most recently
from
August 11, 2026 05:43
2a9e536 to
2dda649
Compare
gomitrah
force-pushed
the
feat/38692-oidc-logout-id-token-hint
branch
from
August 13, 2026 05:53
2dda649 to
e69d67a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The OIDC RP-Initiated Logout redirect built in
buildOIDCEndSessionURLonly sent
client_idandpost_logout_redirect_urito the provider'send_session_endpoint. Some OIDC providers (e.g. Dex) requireid_token_hintto complete logout per the RP-Initiated Logoutspec,
so logout against those providers couldn't be completed correctly.
This stores the
id_tokenreturned by the provider at sign-in in thesession (
session.KeyOIDCIDToken), and passes it back asid_token_hinton logout when present. Sessions that predate thischange, or providers that don't return an
id_token, keep theprevious behavior — the parameter is only added when a token is
actually available.
Testing
Closes #38692.