| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
This test case only contains client_id and client_secret at Basic Authentication header, assuming that there is no client_id and client_secret at form data.
This data class contains creds plus auth method
Retrieve client_id from auth header or the body, then retrieve client via that client_id. After that, compare auth method.
`match` causes coverage error on python 3.10.
|
|
||
| return client | ||
|
|
||
| async def _get_credentials(self, request: Request) -> ClientCredentials: |
There was a problem hiding this comment.
Note: the core extraction logic of client_id and client_secret is as same as before.
Sorry, something went wrong.
|
|
||
| @pytest.mark.anyio | ||
| async def test_wrong_auth_method_without_valid_credentials_fails( | ||
| async def test_wrong_auth_method_fails( |
There was a problem hiding this comment.
Note: test fails as same as before, only exception message has been changed, due to the auth method mismatch.
Sorry, something went wrong.
| # RFC 6749: authentication failures return "invalid_client" | ||
| assert error_response["error"] == "invalid_client" | ||
| assert "Missing or invalid Basic authentication" in error_response["error_description"] | ||
| assert "Expected client_secret_basic authentication method" in error_response["error_description"] |
There was a problem hiding this comment.
Note: test fails as same as before, only exception message has been changed, due to the auth method mismatch.
Sorry, something went wrong.
|
|
||
| @pytest.mark.anyio | ||
| async def test_basic_auth_client_id_mismatch_fails( | ||
| async def test_basic_auth_takes_precedence( |
There was a problem hiding this comment.
Note: the behaviour of the test has been changed. After the changes, basic auth takes precedence over form data, so even if there is a mismatch, the middleware retrieves the client_id from the header.
This behaviour is intended due to RFC 6749 Section 2.3.1:
Including the client credentials in the request-body using the two parameters is NOT RECOMMENDED and SHOULD be limited to clients unable to directly utilize the HTTP Basic authentication scheme (or other password-based HTTP authentication schemes).
If this is inappropriate, alternatives are:
Sorry, something went wrong.
|
@ochafik @pcarleton I saw you were involved in #1334 which added the client_secret_basic auth method, could you have a look at this PR as well? I added my point of view on the issue this PR resolves in #1315 (comment) —* Including the realization that MCP is about OAuth 2.1 draft 13 and not RFC 6749, but that both standards seem to agree that client_id is not required for client_secret_basic * human-crafted em dash |
Sorry, something went wrong.
|
+1, hit this in production via FastMCP (OAuthProxy). The bug compounds for FastMCP-based MCP servers because Concrete repro against a vanilla FastMCP OAuthProxy deploy: # Pure Basic auth - RFC 6749 §2.3.1 compliant
curl -sS -u "$CID:$CSEC" \
-d 'grant_type=authorization_code&code=test&redirect_uri=...' \
http://server/token
# → 401 {"error":"invalid_client","error_description":"Missing client_id"}
# Same creds in POST body
curl -sS \
-d "grant_type=authorization_code&code=test&client_id=$CID&client_secret=$CSEC&redirect_uri=..." \
http://server/token
# → 400 (reaches code_verifier validation; client_id was parsed)Same handler, same input, different carrier. The diff in this PR fixes the Spec-compliant @ai-sdk/mcp clients default to client_secret_basic when |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
This PR implements OAuth client authentication by supporting HTTP Basic authentication as defined in RFC 6749 Section 2.3.1., especially when client_id is provided only from the header.
The key changes are:
Previously, the code would first read client_id from the form body and then validate against the auth method. This caused issues when clients used Basic auth without including client_id in the request body, which is valid per the OAuth spec.
Motivation and Context
How Has This Been Tested?
Unit Test
E2E Test
- Tested with npx @modelcontextprotocol/inspector + OAuth provider mockup, and worked as expected.
ScreenshotsBreaking Changes
Types of changes
Checklist
Additional context