Repository navigation
Persist rotated refresh token after token exchange (AST-195266) - #1622
Merged
cx-sumit-morchhale merged 6 commits intoNov 26, 2026
Merged
Conversation
When IAM returns a new refresh token in the refresh_token grant response, the old one is invalidated. getNewToken dropped it, so the next exchange failed and users had to sign in again. Save it back to the credential store when the stored value is still the one that was exchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Rotate now returns whether it wrote the new value, so the verbose log no longer claims a save when the credential came from a flag or environment variable or was changed by another login. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
cx-rakesh-kadu
requested changes
Nov 24, 2026
cx-rakesh-kadu
requested review from
cx-anurag-dalke,
cx-atish-jadhav and
cx-sumit-morchhale
November 24, 2026 11:48
…e tests - Print a non-verbose warning when the rotated token cannot be saved; the command still succeeds. - Rotate replaces the config file entry atomically under the config file lock (SetKeyIfEqual) and, in auto mode with the keyring unavailable, falls back to the config file only when it already holds the old token. - Soften the Rotate doc comment: the keyring has no compare-and-set. - Add tests for PolicyDisabled and PolicyAuto, the keyring fallback, a failing store, and the warning on a failed save. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
cx-rakesh-kadu
approved these changes
Nov 24, 2026
Co-Authored-By: Claude Sonnet 5.5 <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
getNewTokenreturned only the access token, so a refresh token rotated by IAM in therefresh_tokengrant response was discarded (found by Pedro Fernandes on DevAssist 2.3.70). The stored token then keeps its original expiry and can stop working.getNewTokenInforeturns the full token response.exchangeAPIKeysaves a changed refresh token through the newResolver.Rotate.Rotatereports whether it wrote. It does nothing when the credential comes from--apikeyorCX_APIKEY(those win on resolve). It writes only while the stored value is still the token that was exchanged, so a newer login is not replaced by a stale token.CX_KEYRING_MODE=disabled): the compare and write are atomic under the config file lock (configfile.SetKeyIfEqual).automode with the keyring unavailable: the rotated token is written to the config file, but only if the file already holds the old token (no new plaintext entry is ever created).--debug: "Warning: could not save the refreshed credential: ... You may need to run 'cx auth login' again."Review feedback addressed
--debug.Resolver.muwas not used:RotatecallsexplicitValueandresolve, which take it, and it only guards the in-process override map.)PolicyDisabled,PolicyAuto(working keyring and keyring unavailable), and the warning on a failed save.Automated tests
go test ./internal/configfile/ ./internal/credentialstore/go test -vet=off ./internal/wrappers/ -run ExchangeAPIKey(-vet=offonly becausego vetalready fails on unrelated files)golangci-lint run -c .golangci.yml --new-from-rev=origin/main: 0 new issuesManual test results (live EU tenant, isolated config path, Windows)
disabled: login, then 4 refreshesrequired(Credential Manager): login, then 3 refreshesauto(Credential Manager): login, then 3 refreshesrequiredCX_APIKEY/--apikeymain, 5 runsNot covered
--apikey, so this fix cannot update their copy.cx auth loginstill uses theide-integrationclient.Pairs with Checkmarx/ast-vscode-extension#1576 and Checkmarx/ast-jetbrains-plugin#475 (
cx-mcp-clientlogin).🤖 Generated with Claude Code