fix: preserve existing refresh_token when server omits it in refresh response#2304
Open
ctonneslan wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Conversation
…response Per RFC 6749 Section 6, the authorization server MAY issue a new refresh token in the refresh response. When it does not, the client must preserve the existing one. The current implementation replaces current_tokens with the parsed response as-is, which discards the stored refresh_token when the server omits it. After the first successful refresh, can_refresh_token() returns False and all subsequent refreshes fail, forcing full re-authentication. Many OAuth providers omit refresh_token from refresh responses by default (Google, Auth0 without rotation, Okta in persistent mode). Github-Issue: modelcontextprotocol#2270
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
_handle_refresh_response()replacescurrent_tokenswith the parsed refresh response as-is. When the authorization server does not return a newrefresh_tokenin the response, the previously stored one is lost.After the first successful refresh,
can_refresh_token()returnsFalseand all subsequent refreshes fail, forcing full re-authentication.Per RFC 6749 Section 6, issuing a new refresh token in the refresh response is optional. Many OAuth providers omit it by default (Google, Auth0 without rotation enabled, Okta in persistent token mode).
Fix
Before overwriting
current_tokens, check if the refresh response omitsrefresh_token. If so, preserve the existing one usingmodel_copy(update=...).This matches the RFC wording: if a new refresh token is issued, replace the old one; otherwise keep using the existing one.
Fixes #2270