fix: Preserve AuthMode and fix scope corruption on OAuth token refresh#42
Open
FelixLisczyk wants to merge 1 commit intojoa23:mainfrom
Open
fix: Preserve AuthMode and fix scope corruption on OAuth token refresh#42FelixLisczyk wants to merge 1 commit intojoa23:mainfrom
FelixLisczyk wants to merge 1 commit intojoa23:mainfrom
Conversation
Preserve AuthMode across token refreshes — the OAuth server never returns it, so without explicit preservation it was silently dropped after the first refresh, breaking --assignee me for agent-mode users. Mirrors the existing RefreshToken preservation pattern in refreshTokenLocked. Remove the SanitizeToken call on the raw JSON document in LoadTokenData. Sanitizing the whole document stripped spaces from JSON string values (e.g. scope "read write" → "readwrite"). SaveTokenData already sanitizes individual token fields on write, so the document-level call was redundant and harmful. The legacy plain-string path retains sanitization. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
This PR addresses two remaining gaps in the OAuth token refresh flow after PR #8.
Bug 1 — AuthMode lost after first token refresh
refreshTokenLocked()already preservesRefreshTokenfrom the existing tokenwhen the OAuth server's response omits it. However, the same preservation was missing
for
AuthMode. Since the OAuth protocol never includesauth_modein a refreshresponse, the field is silently dropped on the first refresh. The saved token file
then has an empty
auth_mode, which breaks--assignee meresolution for userswho authenticated in agent mode.
Fix: apply the same "preserve if absent" guard to
AuthModeinrefresher.go,mirroring the existing
RefreshTokenlogic.Bug 2 —
SanitizeTokencorrupts JSON string values containing spacesLoadTokenData()calledSanitizeToken()on the entire raw file content beforeparsing it as JSON.
SanitizeTokenstrips all whitespace characters, which corruptsany JSON string value that contains a space — for example a scope field of
"read write"becomes"readwrite". The JSON structure remained parseable, so thecorruption was silent.
SaveTokenDataalready sanitizes the individualAccessTokenandRefreshTokenfields before writing, so sanitizing the whole document on load is redundant for the
JSON path and actively harmful. The fix moves
SanitizeTokento the legacyplain-string fallback path only, where it is still needed.
Test plan
TestRefresher_PreservesAuthModeOnRefresh— verifiesAuthModeis carried overwhen the refresh response does not include it
TestRefresher_DoesNotOverwriteAuthModeWhenPresent— verifies a newAuthModein the response wins over the old one
TestRefresher_PreservesRefreshTokenWhenAbsent— regression guard for theexisting
RefreshTokenpreservation logic"load token data JSON with spaces in scope"— directly reproduces thespace-stripping bug and verifies the fix
make testpasses (all existing tests remain green)🤖 Generated with Claude Code