Repository navigation
fix(apollo)!: let a refresh through with an expired access token - #251
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 1625914 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| this.tokenSource.deleteAccessToken( | ||
| contextValue.req, | ||
| contextValue.res, | ||
| if (!(e instanceof TokenExpiredError)) { |
Contributor
There was a problem hiding this comment.
if (e instanceof TokenInvalidError) {
return this.rejectInvalidToken(
contextValue,
"access",
accessToken,
e,
);
}
robertmoelker
approved these changes
Oct 8, 2026
BramKaashoek
force-pushed
the
fix/refresh-with-expired-access-token
branch
from
October 8, 2026 12:44
79a438c to
d3dae54
Compare
The gateway answered a request carrying an expired access or data token with a 401 before loading the refresh token, so the first refresh after `exp` always failed. It now loads the refresh token first and, when it loads, clears the expired token and continues without it. BREAKING CHANGE: clients must send the refresh token with refresh requests only; any other request carrying it runs without the expired token instead of getting a 401. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BramKaashoek
force-pushed
the
fix/refresh-with-expired-access-token
branch
from
October 8, 2026 13:33
d3dae54 to
1625914
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
GatewayAuthPlugin.requestDidStartanswers any request that carries an expired access token (or an expired data token) withdeleteAccessToken+ 401, and it does this before the refresh token is loaded. The refresh request is no exception, so a refresh sent while the expired access cookie is still present fails. Only a retry without the access token succeeds. Consumers that treat a failed refresh as a logout sign the user out.Change
The refresh token is now loaded before deciding on an expired access or data token:
The two invalid-token branches now share a
rejectInvalidTokenhelper. Their behaviour and log fields are unchanged.A side effect is that a
CustomerLogout-style mutation sent with an expired access token now runs and revokes the refresh token. Before, it got a 401.hive-router-federated-tokenbehaves similarly (src/plugin.rs,if refreshing), with these differences:Breaking (major)
The gateway can't tell which operation is the refresh. Any request that carries a valid refresh token runs without the expired token, which means anonymously if the expired token was the access token. A resolver that mints an anonymous session would then replace the user's refresh token.
refreshTokenPath, or, for header clients, sendx-refresh-tokenon the refresh mutation alone.INVALID_TOKENand clears the whole session, including a valid refresh token. Before, it returned the expired 401.The changeset and the apollo README document all of this.
Tests
gateway.test.tshas anit.eachover the access, data and refresh token states. For each state it asserts the outcome (continues,UNAUTHENTICATEDorINVALID_TOKEN) and exactly which cookies are cleared. A mutation sweep covers every guard, every delete call, both listeners and the session wipe.A successful refresh clears the access cookie and then sets it again in the same response. This was checked over real HTTP:
🤖 Generated with Claude Code