@@ -1117,7 +1117,7 @@ async def test_wrong_auth_method_without_valid_credentials_fails(
11171117 )
11181118
11191119 # Try to use Basic auth when client_secret_post is registered (without secret in body)
1120- # This should fail because the secret is missing from the expected location
1120+ # This should fail despite that credentials are provided via Basic auth, because the method is wrong
11211121
11221122 credentials = f"{ client_info ['client_id' ]} :{ client_info ['client_secret' ]} "
11231123 encoded_credentials = base64 .b64encode (credentials .encode ()).decode ()
@@ -1138,7 +1138,7 @@ async def test_wrong_auth_method_without_valid_credentials_fails(
11381138 error_response = response .json ()
11391139 # RFC 6749: authentication failures return "invalid_client"
11401140 assert error_response ["error" ] == "invalid_client"
1141- assert "Client secret is required " in error_response ["error_description" ]
1141+ assert "Expected client_secret_post authentication method " in error_response ["error_description" ]
11421142
11431143 @pytest .mark .anyio
11441144 async def test_basic_auth_without_header_fails (
@@ -1183,7 +1183,7 @@ async def test_basic_auth_without_header_fails(
11831183 error_response = response .json ()
11841184 # RFC 6749: authentication failures return "invalid_client"
11851185 assert error_response ["error" ] == "invalid_client"
1186- assert "Missing or invalid Basic authentication" in error_response ["error_description" ]
1186+ assert "Expected client_secret_basic authentication method " in error_response ["error_description" ]
11871187
11881188 @pytest .mark .anyio
11891189 async def test_basic_auth_invalid_base64_fails (
@@ -1279,10 +1279,10 @@ async def test_basic_auth_no_colon_fails(
12791279 assert "Invalid Basic authentication header" in error_response ["error_description" ]
12801280
12811281 @pytest .mark .anyio
1282- async def test_basic_auth_client_id_mismatch_fails (
1282+ async def test_basic_auth_takes_precedence (
12831283 self , test_client : httpx .AsyncClient , mock_oauth_provider : MockOAuthProvider , pkce_challenge : dict [str , str ]
12841284 ):
1285- """Test that client_id mismatch between body and Basic auth fails ."""
1285+ """Test that even client_id at body is invalid, Basic auth passes because of the priority ."""
12861286 client_metadata = {
12871287 "redirect_uris" : ["https://client.example.com/callback" ],
12881288 "client_name" : "Basic Auth Client" ,
@@ -1308,23 +1308,21 @@ async def test_basic_auth_client_id_mismatch_fails(
13081308 # Send different client_id in Basic auth header
13091309 import base64
13101310
1311- wrong_creds = base64 .b64encode (f"wrong-client-id :{ client_info ['client_secret' ]} " .encode ()).decode ()
1311+ creds = base64 .b64encode (f"{ client_info [ 'client_id' ] } :{ client_info ['client_secret' ]} " .encode ()).decode ()
13121312 response = await test_client .post (
13131313 "/token" ,
1314- headers = {"Authorization" : f"Basic { wrong_creds } " },
1314+ headers = {"Authorization" : f"Basic { creds } " },
13151315 data = {
13161316 "grant_type" : "authorization_code" ,
1317- "client_id" : client_info [ "client_id" ] , # Correct client_id in body
1317+ "client_id" : "wrong-client-id" , # Wrong client_id in body
13181318 "code" : auth_code ,
13191319 "code_verifier" : pkce_challenge ["code_verifier" ],
13201320 "redirect_uri" : "https://client.example.com/callback" ,
13211321 },
13221322 )
1323- assert response .status_code == 401
1324- error_response = response .json ()
1325- # RFC 6749: authentication failures return "invalid_client"
1326- assert error_response ["error" ] == "invalid_client"
1327- assert "Client ID mismatch" in error_response ["error_description" ]
1323+
1324+ # Header takes precedence, so this should succeed
1325+ assert response .status_code == 200
13281326
13291327 @pytest .mark .anyio
13301328 async def test_basic_auth_without_client_id_at_body (
0 commit comments