Retain id_token and refresh_token across token refreshes - #160
Merged
Conversation
petrikero
force-pushed
the
fix/retain-tokens-on-refresh
branch
from
June 22, 2026 15:18
19cc6bb to
660624e
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.
Problem
refreshTokenSetsaved therefresh_tokengrant response verbatim as the new session token set. But an OAuth2/OIDC refresh response is a delta, not a full replacement:id_tokenon a refresh, so the storedid_tokenwas wiped on the first refresh.refresh_tokenfrom the response, which would drop it and silently sign the user out.Losing the
id_tokenis the more visible symptom: the CLI can no longer read the user's identity claims (sub/email/name) locally and is forced onto a UserInfo endpoint for everyauth whoami/get kubeconfigcall.Fix
Add
mergeRefreshedTokenSet, which treats the refresh response as a delta over the previous token set:access_tokenalways comes from the response, whileid_tokenandrefresh_tokenare carried forward from the previous set whenever the response omits them.Tests
First unit tests for
pkg/auth:TestMergeRefreshedTokenSet— all-fields, omittedid_token(Ory behavior), omittedrefresh_token(rotation disabled), and access-token-only responses.Notes
Independent correctness fix with no behavior change when the server returns all fields. A separate follow-up will use the now-retained
id_tokento resolve user info from claims and remove the dependency on the sunsetting portal/api/external/userinfoendpoint.