fix(auth): preserve user-agent through oauth flow#2871
Open
go165 wants to merge 1 commit into
Open
Conversation
6bd4fef to
2205c37
Compare
Author
|
Validation update for latest head Local checks also passed:
|
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.
Summary
Preserve a caller-supplied
User-Agentheader across the OAuth discovery and token exchange requests issued byOAuthClientProvider.This keeps auth-flow requests compliant with environments that require
User-Agenton all requests, such as AWS WAF baselines, while only propagating the header that is safe to carry across the resource-server/auth-server boundary.What changed
User-Agentfrom the original MCP request into OAuth metadata discovery requests.User-Agent.Validation
PYTHONPATH=src /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m pytest tests/interaction/auth/test_flow.py::test_oauth_flow_preserves_custom_user_agent_on_auth_requests -qPYTHONPATH=src /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m pytest tests/interaction/auth/test_flow.py::test_an_unauthenticated_request_is_challenged_then_the_full_oauth_flow_connects tests/interaction/auth/test_flow.py::test_oauth_flow_preserves_custom_user_agent_on_auth_requests -qPYTHONPATH=src /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m pytest tests/client/test_auth.py::TestAuthFlow::test_auth_flow_with_valid_tokens -qPYTHONPATH=src /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m pytest tests/client/test_auth.py::TestOAuthFallback::test_refresh_token_request tests/client/test_auth.py::TestOAuthFallback::test_basic_auth_refresh_token -q/home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m ruff check src/mcp/client/auth/oauth2.py src/mcp/client/auth/utils.py tests/interaction/auth/_harness.py tests/interaction/auth/test_flow.py/home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m ruff format --check src/mcp/client/auth/oauth2.py src/mcp/client/auth/utils.py tests/interaction/auth/_harness.py tests/interaction/auth/test_flow.py/home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m pyright --pythonpath /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python src/mcp/client/auth/oauth2.py src/mcp/client/auth/utils.py