Repository navigation
fix: keep the rotated refresh token after session refresh - #1864
Merged
Merged
Conversation
When Refresh Token Rotation is enabled, Salesforce returns a new refresh token on each refresh and invalidates the old one. Store it in conn.refreshToken so that the next refresh on the same connection works. Co-authored-by: Chow Loong Jin <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Thanks for this, I'll close my PR then |
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
When Refresh Token Rotation is enabled on the connected app or External Client App, Salesforce returns a new refresh token on each refresh and invalidates the old one.
oauthRefreshFndid not store the new token inconn.refreshToken, so the next refresh on the same connection sent the invalidated token and failed.This PR passes
refresh_tokenfrom the token response to_establish. When the response has norefresh_token,_establishkeeps the current one, so behavior without rotation is unchanged.Starting March 30, 2027, Salesforce blocks new installations of connected apps and External Client Apps that do not enable and lock Refresh Token Rotation, along with PKCE and a proof-of-possession control. Salesforce's guidance for apps that use Refresh Token Rotation is to save the new refresh token returned on every refresh.
To persist the rotated token, listen to the
refreshevent. Its second argument is the token response:Based on #1837 by @hyperair, with tests added. Supersedes #1837. Also fixes the problem reported in #1789.
Tests
Added
test/connection-refresh.mock.test.ts, which mocks the token endpoint and checks that:conn.refreshTokenrefreshevent receives the rotated refresh tokenReferences