Skip to content

OAuth client: refresh before re-authorizing, and discover before refreshing - #3328

Closed
maxisbey wants to merge 5 commits into
mainfrom
oauth-refresh-on-401
Closed

maxisbey wants to merge 5 commits into
mainfrom
oauth-refresh-on-401

Handle the CIMD issuer change beside the SEP-2352 guard so stale meta…

76542f8
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed Aug 18, 2026 in 12m 5s

Code review found 4 new issues (1 earlier finding still open)

Found 7 candidates, confirmed 5: 4 posted in this review, 1 from earlier reviews still open. See review comments for details.

Details

Severity Count
🔴 Important 1
🟡 Nit 4
🟣 Pre-existing 0
Severity File:Line Issue
🔴 Important src/mcp/client/auth/oauth2.py:768 The new 401-branch Step-5 refresh POSTs the refresh token (and client secret) to the origin-guessed '{resource-server-or
🟡 Nit src/mcp/client/auth/oauth2.py:767 nit, pre-existing extended by this diff: the new 401-branch Step 5 refresh (and the pre-request refresh it complements)
🟡 Nit src/mcp/client/auth/oauth2.py:0 The new CIMD issuer-change guard (elif at lines 655-666: drop tokens, drop cached metadata, re-stamp the record) is gate
🟡 Nit src/mcp/client/auth/oauth2.py:0 [quality] Pre-existing, extended by this PR: '_refresh_token' (lines 497-501) re-implements '_get_token_endpoint()' (lin

Annotations

Check failure on line 768 in src/mcp/client/auth/oauth2.py

See this annotation in the file changed.

@claude claude / Claude Code Review

The new 401-branch Step-5 refresh POSTs the refresh token (and client secret) to the origin-guessed `{resource-server-origin}/token` whenever AS metadata discovery fails, because `_refresh_token` (lines 497-501) still falls back to `urljoin(get_authorizat

The new 401-branch Step-5 refresh POSTs the refresh token (and client secret) to the origin-guessed `{resource-server-origin}/token` whenever AS metadata discovery fails, because `_refresh_token` (lines 497-501) still falls back to `urljoin(get_authorization_base_url(self.context.server_url), "/token")` and, unlike the newly gated pre-request site (lines 594-598), the Step-5 call site is not conditioned on `oauth_metadata is not None`. When PRM succeeded and named an AS that is not at the resour

Check warning on line 767 in src/mcp/client/auth/oauth2.py

See this annotation in the file changed.

@claude claude / Claude Code Review

nit, pre-existing extended by this diff: the new 401-branch Step 5 refresh (and the pre-request refresh it complements) builds the refresh request via the base `_refresh_token()` -> `prepare_token_auth()`, which adds no client authentication for `token_en

nit, pre-existing extended by this diff: the new 401-branch Step 5 refresh (and the pre-request refresh it complements) builds the refresh request via the base `_refresh_token()` -> `prepare_token_auth()`, which adds no client authentication for `token_endpoint_auth_method="private_key_jwt"` (oauth2.py:271-274 explicitly defers the assertion to "the provider that implements it"), but `PrivateKeyJWTOAuthProvider` only adds its `client_assertion` in `_exchange_token_client_credentials` (src/mcp/cl