GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: preserve existing refresh_token when server omits it in refresh response · Pull Request #2304 · modelcontextprotocol/python-sdk

Conversation

@ghost

@ghost ghost commented Mar 17, 2026

Copy link
Copy Markdown

Problem

_handle_refresh_response() replaces current_tokens with the parsed refresh response as-is. When the authorization server does not return a new refresh_token in the response, the previously stored one is lost.

After the first successful refresh, can_refresh_token() returns False and 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 omits refresh_token. If so, preserve the existing one using model_copy(update=...).

if (
    not token_response.refresh_token
    and self.context.current_tokens
    and self.context.current_tokens.refresh_token
):
    token_response = token_response.model_copy(
        update={"refresh_token": self.context.current_tokens.refresh_token}
    )

This matches the RFC wording: if a new refresh token is issued, replace the old one; otherwise keep using the existing one.

Fixes #2270

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@c-tonneslan
fix: preserve existing refresh_token when server omits it in refresh …
43e954f
…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: #2270
@maxisbey

maxisbey commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution! Closing this in favour of #2271 as that predates this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@maxisbey maxisbey closed this Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

_handle_refresh_response discards existing refresh_token when server omits it

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@maxisbey @c-tonneslan
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.