Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/provider/qwen_code/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
3. 拿到 token 对后把 `expires_in` 现算成 `expires_at` 一并落库(不猜 TTL);
4. 账号标识从 `GET {OAUTH_HOST}/api/oauth/userinfo` 尽力补,读不到不算登录失败。

旧版 `chat.qwen.ai/api/v2/oauth/*` 已下线:该路径现在回阿里云 WAF 的 HTML
旧版网页版站点(`qwen.ai` 的 chat 前台)的 `/api/v2/oauth/*` 已下线:
该路径现在回阿里云 WAF 的 HTML
验证页(HTTP 200),拿它 `response.json()` 会抛 `JSONDecodeError` → 500。
"""

Expand Down Expand Up @@ -70,7 +71,8 @@ def _session(state: str, pending: _Pending) -> AuthSession:
`verification_uri_complete` 指向 `/device`,打开只是聊天首页,**不出现
设备码确认框**(2026-12-04 浏览器实测)。
"""
origin = urlparse(pending.verification_uri or "https://chat.qwen.ai/device")
#: `verification_uri` 只来自 start():为空已被判协议违规,故这里无兜底。
origin = urlparse(pending.verification_uri)
query = urlencode({"user_code": pending.user_code, "client": "cli"})
auth_url = f"{origin.scheme}://{origin.netloc}/authorize?{query}"
return AuthSession(flow=AuthFlow.POLL, state=state, auth_url=auth_url,
Expand Down
10 changes: 5 additions & 5 deletions tests/provider/qwen_code/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def _form(request: httpx.Request) -> dict[str, list[str]]:

def _device_code_response(**overrides) -> httpx.Response:
payload = {"device_code": "dc", "user_code": "WXYZ-9876",
"verification_uri": "https://chat.qwen.ai/device",
"verification_uri": "https://auth.qwen.ai/device",
"verification_uri_complete":
"https://chat.qwen.ai/device?user_code=WXYZ-9876",
"https://auth.qwen.ai/device?user_code=WXYZ-9876",
"expires_in": 600, "interval": 5}
payload.update(overrides)
return httpx.Response(200, json=payload)
Expand All @@ -48,7 +48,7 @@ def handler(request: httpx.Request) -> httpx.Response:
session = await oauth.start("admin")
assert session.flow is AuthFlow.POLL
assert session.auth_url == (
"https://chat.qwen.ai/authorize?user_code=WXYZ-9876&client=cli")
"https://auth.qwen.ai/authorize?user_code=WXYZ-9876&client=cli")
assert session.user_code == "WXYZ-9876"
assert session.interval == 5
assert session.state != "dc"
Expand All @@ -67,7 +67,7 @@ def handler(request: httpx.Request) -> httpx.Response:

session = await _oauth(handler).start("admin")
assert session.auth_url == (
"https://chat.qwen.ai/authorize?user_code=WXYZ-9876&client=cli")
"https://auth.qwen.ai/authorize?user_code=WXYZ-9876&client=cli")


async def test_start_reuses_pending_so_displayed_code_stays_pollable():
Expand Down Expand Up @@ -109,7 +109,7 @@ async def test_start_defaults_interval_when_absent_or_invalid():
for interval in (None, "5", True, -1):
def handler(request: httpx.Request, interval=interval) -> httpx.Response:
body = {"device_code": "dc", "user_code": "U",
"verification_uri": "https://chat.qwen.ai/device"}
"verification_uri": "https://auth.qwen.ai/device"}
if interval is not None:
body["interval"] = interval
return httpx.Response(200, json=body)
Expand Down