Skip to content

Commit b54801d

Browse files
committed
tidy: simplify token endpoint auth method validation
1 parent 496df55 commit b54801d

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

src/mcp/server/auth/handlers/token.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ class RefreshTokenRequest(BaseModel):
3232

3333

3434
class NoneCredentials(BaseModel):
35+
auth_method: Literal["none"] = "none"
3536
client_id: str
3637
client_secret: None = None
3738

3839

3940
class PostCredentials(BaseModel):
41+
auth_method: Literal["client_secret_post"] = "client_secret_post"
4042
client_id: str
4143
# we use the client_secret param, per https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1
4244
client_secret: str
@@ -47,6 +49,7 @@ class FormCredentials(RootModel[PostCredentials | NoneCredentials]):
4749

4850

4951
class BasicCredentials(BaseModel):
52+
auth_method: Literal["client_secret_basic"] = "client_secret_basic"
5053
client_id: str
5154
client_secret: str
5255

@@ -146,15 +149,8 @@ async def handle(self, request: Request):
146149
client_id=credentials.client_id,
147150
client_secret=credentials.client_secret,
148151
)
149-
match client_info.token_endpoint_auth_method:
150-
case "none" if not isinstance(credentials, NoneCredentials):
151-
raise AuthenticationError("Invalid credentials for client token_endpoint_auth_method")
152-
case "client_secret_post" if not isinstance(credentials, PostCredentials):
153-
raise AuthenticationError("Invalid credentials for client token_endpoint_auth_method")
154-
case "client_secret_basic" if not isinstance(credentials, BasicCredentials):
155-
raise AuthenticationError("Invalid credentials for client token_endpoint_auth_method")
156-
case _:
157-
pass
152+
if client_info.token_endpoint_auth_method != credentials.auth_method:
153+
raise AuthenticationError("Invalid credentials for client token_endpoint_auth_method")
158154
except AuthenticationError as e:
159155
return self.response(
160156
TokenErrorResponse(

0 commit comments

Comments
 (0)