OAuth refresh uses MCP endpoint instead of discovered protected-resource audience - #1084
Merged
DaleSeo merged 1 commit intoJul 29, 2026
Conversation
tsarlandie-oai
marked this pull request as ready for review
July 29, 2026 20:21
DaleSeo
approved these changes
Jul 29, 2026
DaleSeo
left a comment
Member
There was a problem hiding this comment.
Thanks for the fix, @tsarlandie-oai!
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
AuthorizationManagercorrectly resolves the OAuth resource from protected-resource metadata:Both initial authorization and authorization-code exchange correctly use:
However,
AuthorizationManager::refresh_token()uses:Consequently, refresh can request a different token audience than the one used for the original authorization.
Reproduction
Configure an MCP endpoint:
Return protected-resource metadata identifying:
{ "resource": "https://server.example", "authorization_servers": [ "https://auth.example" ] }Complete OAuth authorization successfully.
Refresh the resulting access token.
Actual behavior
The refresh request contains:
Authorization servers enforcing audience binding can reject this with:
Expected behavior
The refresh request should use the validated, discovered protected-resource identifier:
This preserves the same audience across authorization, code exchange, and refresh, consistent with RFC 8707 and RFC 9728.
Fix
let mut refresh_request = oauth_client .exchange_refresh_token(&refresh_token_value) - .add_extra_param("resource", self.base_url.to_string()); + .add_extra_param("resource", self.oauth_resource().await);The existing endpoint fallback remains unchanged when protected-resource metadata does not provide a discovered resource.
Regression coverage
Add
refresh_token_uses_discovered_protected_resource, which runs the complete protected-resource discovery, authorization, authorization-code exchange, and refresh flow using the existing recording OAuth HTTP client. It verifies:/mcpendpoint.refresh_token_includes_resource_parametertest continues to cover endpoint fallback when no resource is discovered.The new regression test fails before the fix because the refresh audience is
https://mcp.example.com/mcpwhile the other two audiences arehttps://mcp.example.com.Downstream impact
Clients currently have to intercept and rewrite SDK-generated refresh requests to maintain the correct audience. Fixing this upstream allows that workaround to be removed.
Validation
cargo test -p rmcp --features auth --libcargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warnings