Skip to content

fix: omit OAuth resource on token refresh - #2590

Closed
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/oauth-refresh-resource-param
Closed

fix: omit OAuth resource on token refresh#2590
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/oauth-refresh-resource-param

Conversation

@he-yufeng

Copy link
Copy Markdown

Summary

  • omit RFC 8707 resource from refresh_token requests
  • normalize root protected-resource URLs so Pydantic's bare-domain trailing slash does not leak into the OAuth resource value
  • keep resource on authorization and initial token exchange requests

Fixes #2578.

To verify

  • python -m py_compile src\mcp\client\auth\oauth2.py tests\client\test_auth.py
  • uv run pytest tests\client\test_auth.py -q --basetemp .tmp\pytest -p no:cacheprovider
  • uv run ruff check src\mcp\client\auth\oauth2.py tests\client\test_auth.py
  • uv run ruff format --check src\mcp\client\auth\oauth2.py tests\client\test_auth.py
  • uv run pyright src\mcp\client\auth\oauth2.py tests\client\test_auth.py
  • git diff --check

@he-yufeng

Copy link
Copy Markdown
Author

Closing this during backlog cleanup. The python-sdk queue has too many open PRs, and this older/no-human-signal item is lower priority than the remaining PRs that have recent validation, review discussion, or clearer current value. I can reopen or refresh it if maintainers want this specific change.

@he-yufeng he-yufeng closed this Jun 10, 2026
fede-kamel added a commit to fede-kamel/python-sdk that referenced this pull request Aug 19, 2026
…railing slash from PRM resource

Two compounding bugs broke silent token refresh against Microsoft Entra
ID v2.0 (AADSTS9010010), causing MCP servers using Entra OAuth to lose
authentication after ~1 hour:

- _refresh_token() sent the RFC 8707 resource parameter on
  refresh_token grants, which Entra v2.0 strictly rejects since
  March 2026. The parameter is now omitted from refresh requests.
- Pydantic's AnyHttpUrl normalizes bare-domain PRM resource URLs to
  include a trailing slash, so the resource audience never matched the
  IdP app registration. get_resource_url() now strips the slash, but
  only when the path is exactly "/" with no query or fragment - RFC
  9728 requires exact-string identity, so intentional trailing slashes
  on deeper paths are preserved.

Implements the approach maintainers endorsed when consolidating earlier
attempts (modelcontextprotocol#2590, since closed unmerged; see discussion on modelcontextprotocol#2645/modelcontextprotocol#2646).

Fixes modelcontextprotocol#2578
fede-kamel added a commit to fede-kamel/python-sdk that referenced this pull request Aug 20, 2026
…railing slash from PRM resource

Two compounding bugs broke silent token refresh against Microsoft Entra
ID v2.0 (AADSTS9010010), causing MCP servers using Entra OAuth to lose
authentication after ~1 hour:

- _refresh_token() sent the RFC 8707 resource parameter on
  refresh_token grants, which Entra v2.0 strictly rejects since
  March 2026. The parameter is now omitted from refresh requests.
- Pydantic's AnyHttpUrl normalizes bare-domain PRM resource URLs to
  include a trailing slash, so the resource audience never matched the
  IdP app registration. get_resource_url() now strips the slash, but
  only when the path is exactly "/" with no query or fragment - RFC
  9728 requires exact-string identity, so intentional trailing slashes
  on deeper paths are preserved.

Implements the approach maintainers endorsed when consolidating earlier
attempts (modelcontextprotocol#2590, since closed unmerged; see discussion on modelcontextprotocol#2645/modelcontextprotocol#2646).

Fixes modelcontextprotocol#2578
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.

OAuth token refresh sends RFC 8707 resource parameter that Entra ID v2.0 rejects (AADSTS9010010)

1 participant