Skip to content

Commit 2eb8c01

Browse files
authored
refactor COD-75:删掉 qwen_code 设备码授权 URL 的死兜底 (#115)
1 parent e2d4f4c commit 2eb8c01

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎src/provider/qwen_code/oauth.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
3. 拿到 token 对后把 `expires_in` 现算成 `expires_at` 一并落库(不猜 TTL);
1414
4. 账号标识从 `GET {OAUTH_HOST}/api/oauth/userinfo` 尽力补,读不到不算登录失败。
1515
16-
旧版 `chat.qwen.ai/api/v2/oauth/*` 已下线:该路径现在回阿里云 WAF 的 HTML
16+
旧版网页版站点(`qwen.ai` 的 chat 前台)的 `/api/v2/oauth/*` 已下线:
17+
该路径现在回阿里云 WAF 的 HTML
1718
验证页(HTTP 200),拿它 `response.json()` 会抛 `JSONDecodeError` → 500。
1819
"""
1920

@@ -69,7 +70,8 @@ def _session(state: str, pending: _Pending) -> AuthSession:
6970
`verification_uri_complete` 指向 `/device`,打开只是聊天首页,**不出现
7071
设备码确认框**(2026-12-04 浏览器实测)。
7172
"""
72-
origin = urlparse(pending.verification_uri or "https://chat.qwen.ai/device")
73+
#: `verification_uri` 只来自 start():为空已被判协议违规,故这里无兜底。
74+
origin = urlparse(pending.verification_uri)
7375
query = urlencode({"user_code": pending.user_code, "client": "cli"})
7476
auth_url = f"{origin.scheme}://{origin.netloc}/authorize?{query}"
7577
return AuthSession(flow=AuthFlow.POLL, state=state, auth_url=auth_url,

‎tests/provider/qwen_code/test_oauth.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def _form(request: httpx.Request) -> dict[str, list[str]]:
2929

3030
def _device_code_response(**overrides) -> httpx.Response:
3131
payload = {"device_code": "dc", "user_code": "WXYZ-9876",
32-
"verification_uri": "https://chat.qwen.ai/device",
32+
"verification_uri": "https://auth.qwen.ai/device",
3333
"verification_uri_complete":
34-
"https://chat.qwen.ai/device?user_code=WXYZ-9876",
34+
"https://auth.qwen.ai/device?user_code=WXYZ-9876",
3535
"expires_in": 600, "interval": 5}
3636
payload.update(overrides)
3737
return httpx.Response(200, json=payload)
@@ -48,7 +48,7 @@ def handler(request: httpx.Request) -> httpx.Response:
4848
session = await oauth.start("admin")
4949
assert session.flow is AuthFlow.POLL
5050
assert session.auth_url == (
51-
"https://chat.qwen.ai/authorize?user_code=WXYZ-9876&client=cli")
51+
"https://auth.qwen.ai/authorize?user_code=WXYZ-9876&client=cli")
5252
assert session.user_code == "WXYZ-9876"
5353
assert session.interval == 5
5454
assert session.state != "dc"
@@ -67,7 +67,7 @@ def handler(request: httpx.Request) -> httpx.Response:
6767

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

7272

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

0 commit comments

Comments
 (0)