Title: fix: preserve existing refresh_token when server omits it in refresh response · Pull Request #2304 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix: preserve existing refresh_token when server omits it in refresh response · Pull Request #2304 · modelcontextprotocol/python-sdk
X Title: fix: preserve existing refresh_token when server omits it in refresh response · Pull Request #2304 · modelcontextprotocol/python-sdk
Description: 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
Open Graph Description: 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 ...
X Description: 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 ...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2304
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:38d973a2-0f1d-4679-a001-2e26a820162d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DA34:1E445D:28FD4:37D9A:6A5A3FA0 |
| html-safe-nonce | b7346c5df35a87902cf06904313596ae597a17dc62235b2379edeec169fa48ac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTM0OjFFNDQ1RDoyOEZENDozN0Q5QTo2QTVBM0ZBMCIsInZpc2l0b3JfaWQiOiI1Njc1NjQyMzIzODY4NDY3MTA0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c1ef299e2fa5a6740ecbe3190de718c599bf657a156e0fc5dd16894d86816089 |
| hovercard-subject-tag | pull_request:3410715027 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2304/files |
| twitter:image | https://avatars.githubusercontent.com/u/10137?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/10137?s=400&v=4 |
| og:image:alt | 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 ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 19c67ad7579d2401ff06e88a32ef45460fbb40fab3191c7f7582d5e166f326fc |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e618485bff22dab2ef1ffb4e34e4e6626688df69 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width