File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed
src/mcp/server/auth/handlers
tests/server/fastmcp/auth Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -74,12 +74,20 @@ async def handle(self, request: Request) -> Response:
74
74
),
75
75
status_code = 400 ,
76
76
)
77
- if set (client_metadata .grant_types ) != {"authorization_code" , "refresh_token" }:
77
+ grant_types_set = set (client_metadata .grant_types )
78
+ valid_sets = [
79
+ {"authorization_code" , "refresh_token" },
80
+ {"client_credentials" },
81
+ ]
82
+
83
+ if grant_types_set not in valid_sets :
78
84
return PydanticJSONResponse (
79
85
content = RegistrationErrorResponse (
80
86
error = "invalid_client_metadata" ,
81
- error_description = "grant_types must be authorization_code "
82
- "and refresh_token" ,
87
+ error_description = (
88
+ "grant_types must be authorization_code and refresh_token "
89
+ "or client_credentials"
90
+ ),
83
91
),
84
92
status_code = 400 ,
85
93
)
Original file line number Diff line number Diff line change @@ -1001,9 +1001,31 @@ async def test_client_registration_invalid_grant_type(
1001
1001
assert error_data ["error" ] == "invalid_client_metadata"
1002
1002
assert (
1003
1003
error_data ["error_description" ]
1004
- == "grant_types must be authorization_code and refresh_token"
1004
+ == (
1005
+ "grant_types must be authorization_code and "
1006
+ "refresh_token or client_credentials"
1007
+ )
1008
+ )
1009
+
1010
+ @pytest .mark .anyio
1011
+ async def test_client_registration_client_credentials (
1012
+ self , test_client : httpx .AsyncClient
1013
+ ):
1014
+ client_metadata = {
1015
+ "redirect_uris" : ["https://client.example.com/callback" ],
1016
+ "client_name" : "CC Client" ,
1017
+ "grant_types" : ["client_credentials" ],
1018
+ }
1019
+
1020
+ response = await test_client .post (
1021
+ "/register" ,
1022
+ json = client_metadata ,
1005
1023
)
1006
1024
1025
+ assert response .status_code == 201 , response .content
1026
+ client_info = response .json ()
1027
+ assert client_info ["grant_types" ] == ["client_credentials" ]
1028
+
1007
1029
1008
1030
class TestAuthorizeEndpointErrors :
1009
1031
"""Test error handling in the OAuth authorization endpoint."""
You can’t perform that action at this time.
0 commit comments