FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

OAuth TokenHandler Enhancement: Authorization Header Fallback Support by ChenyangLi4288 · Pull Request #1316 · modelcontextprotocol/python-sdk · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
17 changes: 15 additions & 2 deletions src/mcp/server/auth/handlers/token.py
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import hashlib
import time
import urllib.parse
from dataclasses import dataclass
from typing import Annotated, Any, Literal

Expand Down Expand Up @@ -92,8 +93,20 @@ def response(self, obj: TokenSuccessResponse | TokenErrorResponse):

async def handle(self, request: Request):
try:
form_data = await request.form()
token_request = TokenRequest.model_validate(dict(form_data)).root
form_data = dict(await request.form())

# Try to get client credentials from header if missing in body
if "client_id" not in form_data:
auth_header = request.headers.get("Authorization")
if auth_header and auth_header.startswith("Basic "):
encoded = auth_header.split(" ")[1]
decoded = base64.b64decode(encoded).decode("utf-8")
client_id, _, client_secret = decoded.partition(":")
client_secret = urllib.parse.unquote(client_secret)
form_data.setdefault("client_id", client_id)
form_data.setdefault("client_secret", client_secret)

token_request = TokenRequest.model_validate(form_data).root
except ValidationError as validation_error:
return self.response(
TokenErrorResponse(
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL