Skip to content

Commit 0c207d2

Browse files
author
OpenClaw AI
committed
fix(oauth): preserve existing refresh_token when server omits it
Per RFC 6749 Section 6, the authorization server MAY issue a new refresh token in the refresh response. If the server does not issue a new refresh token, the client must preserve the existing one. This fix preserves the existing refresh_token when the OAuth server's refresh response omits it, which is common for providers like Google, Auth0, and Okta. Fixes #2270
1 parent 62eb08e commit 0c207d2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/mcp/client/auth/oauth2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,17 @@ async def _handle_refresh_response(self, response: httpx.Response) -> bool: # p
458458
content = await response.aread()
459459
token_response = OAuthToken.model_validate_json(content)
460460

461+
# Per RFC 6749 Section 6, the server MAY issue a new refresh token.
462+
# If the response omits it, preserve the existing one.
463+
if (
464+
not token_response.refresh_token
465+
and self.context.current_tokens
466+
and self.context.current_tokens.refresh_token
467+
):
468+
token_response = token_response.model_copy(
469+
update={"refresh_token": self.context.current_tokens.refresh_token}
470+
)
471+
461472
self.context.current_tokens = token_response
462473
self.context.update_token_expiry(token_response)
463474
await self.context.storage.set_tokens(token_response)

0 commit comments

Comments
 (0)