Skip to content

fix(oauth): preserve existing refresh_token when refresh response omits it#2271

Open
oedokumaci wants to merge 1 commit intomodelcontextprotocol:mainfrom
oedokumaci:fix/preserve-refresh-token
Open

fix(oauth): preserve existing refresh_token when refresh response omits it#2271
oedokumaci wants to merge 1 commit intomodelcontextprotocol:mainfrom
oedokumaci:fix/preserve-refresh-token

Conversation

@oedokumaci
Copy link

@oedokumaci oedokumaci commented Mar 11, 2026

Fixes #2270

Per RFC 6749 Section 6, the authorization server MAY issue a new refresh token in the refresh response. When it doesn't, _handle_refresh_response overwrites the stored token as-is, discarding the existing refresh_token. After the first successful refresh, can_refresh_token() returns False and subsequent refreshes fail.

This preserves the existing refresh_token when the response omits one, using model_copy(update=...).

Also removes # pragma: no cover from _handle_refresh_response (added in a bulk coverage baseline, not intentional) and adds tests covering all branches: success with preservation, success with rotation, no prior tokens, non-200 failure, and invalid JSON.

Note: #2270 hasn't received the ready for work label yet. Submitting this early since the fix is small and self-contained. Happy to wait or adjust based on maintainer feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_handle_refresh_response discards existing refresh_token when server omits it

1 participant