Repository navigation
fix: save refreshed token before onRefreshEnd runs - #9
Merged
Merged
Conversation
getAccessToken() saved the token returned by acquireAccessToken() only after acquireAccessToken() had called onRefreshEnd in its finally block. Applications that hold an inter-process lock between onRefreshStart and onRefreshEnd released the lock before the new token was stored, so another process could take the lock, read the old refresh token from storage, and reuse it. With refresh token rotation this counts as reuse and revokes the session. acquireAccessToken() now sets and saves the token itself, inside the try block, so the save callback runs before onRefreshEnd. This applies to a normal refresh and to tokens returned by onRefreshStart or onRefreshError. onRefreshEnd still runs on failure. Adds GuzzleMiddleware tests for the callback order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The $tokenSave typed property has no default, so reading it before setTokenSaveCallback() was called threw an Error. Use isset(), as for the other callbacks. Co-Authored-By: Claude Opus 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.
Save the acquired token via the token-save callback before
onRefreshEndruns, for normal refreshes and for tokens returned byonRefreshStartoronRefreshError.onRefreshEndstill runs on failure.Before this change, an application holding an inter-process lock between
onRefreshStartandonRefreshEndreleased it before the new token was saved. Another process could then read the old, already-rotated refresh token from storage and reuse it, which revokes the session.Also fixes
setAccessToken()throwing anErrorwhen no token-save callback was set.Once released, the Upsun CLI workaround from upsun/cli#194 (refreshing inside
on_refresh_startvia aConnectorsubclass) can be removed.🤖 Generated with Claude Code