-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: preserve existing refresh_token when server omits it in refresh response #2274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+11
−0
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Per CLAUDE.md:28, bug fixes require regression tests, but this PR only modifies the source file. Consider adding a test in
tests/client/test_auth.pythat verifies_handle_refresh_responsepreserves the existing refresh_token when the server omits it — otherwise a future refactor could silently reintroduce #2270.Extended reasoning...
Summary
The repository's
CLAUDE.mdexplicitly states at line 28: "Bug fixes require regression tests". This PR fixes a real bug (#2270 — refresh tokens being lost when the OAuth server omits them in the refresh response), but only modifiessrc/mcp/client/auth/oauth2.py. No test file is touched, and a grep for_handle_refresh_responseacrosstests/returns zero matches.Why this matters
The only existing refresh-related test is
test_refresh_token_request(test_auth.py:610), which validates request building — it verifies the outgoing POST body containsgrant_type=refresh_tokenand the correct refresh_token value. However, nothing tests the response handling path. The specific behavior this PR introduces (preserving the old refresh token when the new response omits it) is completely unverified by the test suite.While the method carries a
# pragma: no coverannotation, that directive only excludes it from coverage metrics. It does not exempt the fix from the project's documented regression-test requirement. The annotation predates this PR and was likely added because the method is exercised indirectly through the httpx auth-flow generator, which is awkward to drive in unit tests — but the method itself takes a plainhttpx.Responseand is trivial to test directly.Step-by-step proof
Bug fixes require regression tests.changed-files count="1"→ onlysrc/mcp/client/auth/oauth2.py._handle_refresh_responseintests/→ no matches.test_refresh_token→ only findstest_refresh_token_request(line 610), which calls_refresh_token()(request builder), not_handle_refresh_response()(response handler).Suggested fix
A regression test can follow the existing patterns in
test_auth.py(which already constructshttpx.Responseobjects directly — see line 108). For example:A complementary test verifying that a new refresh_token in the response correctly replaces the old one would also be valuable.
Severity rationale
This is a nit rather than a blocker: the code change itself is correct and RFC-compliant. The concern is purely about test coverage per the project's own documented conventions. However, given that this bug (lost refresh tokens with Google/Auth0/Okta) was painful enough to warrant a fix, a regression test is worthwhile insurance against it recurring.