Extract OAuth flow logic into reusable components for proxy use cases
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- python, typescript
- Lĩnh vực
- authentication, backend-api-design
Hướng nghiên cứu
Issue không nêu tên file hay test nào. Hãy bắt đầu bằng cách tìm implementation OAuth hiện có cùng các helper cho discovery, đăng ký, interactive flow, lấy token và lưu trữ, sau đó xem lại #1240 và các yêu cầu của maintainer. Xác thực một thiết kế dạng module, có thể tiếp tục lại, bằng các bản phác thảo TypeScript trước khi phối hợp các thay đổi tương đương trong Python; được coi là hoàn tất khi các client flow hiện có vẫn hoạt động và các trường hợp sử dụng proxy có thể chặn request rồi tiếp tục quy trình xác thực.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Refactor OAuth implementation so the flow logic and state machine are usable by server-side proxy services, not just client-side browser flows.
Problem
The SDK's OAuth implementation is designed for local client-side flows (opening a browser locally). The business logic is embedded inside an httpx auth module, making it hard to reuse for other scenarios.
While individual helper functions have been extracted (PKCE utilities, token exchange, discovery), the core state machine that orchestrates the OAuth flow is not reusable. Proxy services that need to perform OAuth on behalf of users currently have to reimplement significant portions of the flow themselves — and when the SDK updates its OAuth logic, those reimplementations can fall out of sync.
Goal
- Make the OAuth portions of the SDK compatible with proxy/gateway services that currently use custom workarounds
- When an issue is fixed in the SDK, updating the SDK version should fix it everywhere — no custom OAuth reimplementations needed
- Keep existing client-side flows working
Design Requirements (from maintainer discussion, Feb 2026)
Modularization into zones: Break the monolithic OAuth flow into modular, overridable pieces:
- Discovery — obtaining and potentially customizing discovery URLs
- Client Registration — dynamic client registration
- Interactive Flow — authorization URL generation, redirect handling
- Token Fetching — code exchange, refresh, new token extensions (XA, WIF)
- Token Storage — pluggable storage (already exists)
Key requirements:
- Each zone should operate as a pure function requiring minimal state
- Every HTTP request in the flow must be interceptable — allow injection of a custom HTTP client/fetch interface (httpx client in Python, fetch in TypeScript) for custom headers, metrics, response handling
- Support an "Auth Required" state as an SDK primitive — when a server responds with 401/403 mid-flow, the SDK should capture discovery metadata, scope, and WWW-Authenticate info and surface it so the calling application can handle it (rather than assuming auth happens upfront)
- The flow must be resumable — a caller should be able to pick up an auth flow at any point (e.g., after a redirect returns on a different machine/request)
- Support bypassing discovery when configuration is provided directly (important for enterprise environments with broken discovery)
- Support new token-getting extensions (XA, WIF) that don't require interactive flows
Next steps:
- Draft code sketches (potentially TypeScript first) to validate the modular function approach
- Cross-SDK coordination — this applies to both Python and TypeScript SDKs
Related
- #1240 - Implement OAuth relying on Authlib
- #2053 - Replace Field(description=...) with docstrings in auth models
- Ngôn ngữ chính
- Python
- Star
- 24.3k
- Fork
- 4k
- Merge trung bình
- 1 ngày 19 phút
- Pull request đã merge (30 ngày)
- 29
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/python-sdk
-
Streamable HTTP client logs a WARNING for valid 202 Accepted on session termination (DELETE) Đang mởv1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
modelcontextprotocol/python-sdk#3546 · 5 bình luận ·
-
v1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
modelcontextprotocol/python-sdk#3545 · 1 bình luận ·
-
v1 v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
modelcontextprotocol/python-sdk#3508 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
modelcontextprotocol/python-sdk#3504 ·
-
v1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
modelcontextprotocol/python-sdk#3492 · 1 bình luận ·
Tất cả issue của modelcontextprotocol/python-sdk
Issue tương tự
-
Add: hunch Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
DiamondLightSource/dodal#2211 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
openml/openml-python#1749 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
sipyourdrink-ltd/bernstein#6191 ·