modelcontextprotocol / modelcontextprotocol/python-sdk

OAuth TokenHandler should check Authorization header for client credentials

Đang mở
#1,315 6 bình luận 2 reaction 1 người được giao Xem trên GitHub

@pcarleton đang làm issue này rồi.

Từ ngày 4/6/2026.

auth enhancement
Ngôn ngữ chính
Python
Star
24.3k
Fork
4k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
31

Mô tả

Description

Currently, TokenHandler assumes that the Token request's body contains client credentials. However, some OAuth requests would contain client credentials in Authorization header:
Image

In this case, it would throw ValidationError even though client credentials are provided in request header.

Can we add a fallback such that if client_id is not found in formData, we try to get it from header? e.g.

async def handle(self, request: Request):
    try:
        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(
                error="invalid_request",
                error_description=stringify_pydantic_error(validation_error),
            )
        )
    ...

Thanks.

References

No response

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.