[Bug] zcode login 失败:oauth/cli/init 端点在生产后端 404(空响应体)导致 OAuth response is not valid JSON
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
提交前确认 · Pre-submission checklist
- 我已搜索过现有 issue,确认这不是重复提议 / I searched existing issues and confirmed this isn't a duplicate.
- 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
问题类别 · Category
缺陷 / Bug(CLI 登录)
涉及的 Agent 框架 · Agent framework
ZCode Agent(自研)
问题描述 · Bug description
桌面版自带的 CLI(resources/glm/zcode.cjs,0.16.3)执行 zcode login 立即失败:
Error: OAuth response is not valid JSON
退出码 1,未打开浏览器、未进入任何授权流程。这导致独立 CLI 完全无法认证——连带 --prompt 无头模式也无法使用(报 "Model config is missing"),桌面端的登录态不会共享给独立 CLI 进程。
根因分析 · Root cause
从 bundle 反混淆出的登录流程:login 走 Z.AI 设备流,第一步 POST 到默认 base https://zcode.z.ai/api/v1 下的 /oauth/cli/init。各端点实测(Windows 11 + curl):
| URL | 结果 |
|---|---|
POST https://zcode.z.ai/api/v1/oauth/cli/init |
404,空响应体(CLI 实际命中的端点) |
POST https://zcode.z.ai/oauth/cli/init(无 /api/v1 前缀) |
307 → /cn/oauth/cli/init(网站路由,非 API) |
POST https://api.z.ai/api/v1/oauth/cli/init |
JSON {"code":500,"msg":"404 NOT_FOUND"}(路由不存在) |
POST https://open.bigmodel.cn/api/v1/oauth/cli/init |
同上,业务 404 |
https://zcode.chatglm.site(bundle 中出现的另一常量域) |
TLS 握手失败,站点不可达 |
空响应体 + JSON.parse("") → 正是 "OAuth response is not valid JSON" 的来源。即:CLI 硬编码的设备流端点(oauth/cli/init / oauth/cli/poll/*)在当前生产后端上不存在。对照:桌面 App(app.asar)的登录用的是 https://zcode.z.ai/api/v1/oauth/token(授权码流程),说明 /api/v1/oauth/* 路由族是存在的,只是 CLI 依赖的 cli/init 子路径未部署(或 base 已迁移但 CLI 常量滞后)。
另:login 子命令没有 --provider 之类的切换项,BigModel 授权码流程客户端(bigmodel.cn/login + /api/auth/tokenByAuthCode)在 bundle 中存在但 CLI 登录入口未暴露使用路径。
复现步骤 · Reproduce
- Windows 安装桌面版 v3.7.x(自带 CLI 0.16.3);
node <安装目录>\resources\glm\zcode.cjs login;- 立即输出
Error: OAuth response is not valid JSON,退出码 1。
网络侧已排除:open.bigmodel.cn、api.z.ai 等域从本机均可达且正常返回 JSON,无代理干扰。
期望行为 · Expected behavior
zcode login能完整走通设备流(部署/恢复oauth/cli/*端点,或把 CLI base 指向实际存在该路由的后端);- 或为无桌面环境的场景提供非浏览器认证方式(如 API key / 环境变量,GLM Coding Plan 已有 API key 机制,可在 CLI 侧暴露);
- 至少:当响应体为空/非 JSON 时给出可诊断的错误信息(含 HTTP 状态码与 URL),而不是误导性的 JSON 解析错误。
影响 · Impact
- 独立 CLI 无法登录 →
--prompt无头模式、app-server等一切需要模型访问的 CLI 能力全部不可用; - 这正是 #29(P1)诉求的前置阻塞项:即便有非交互入口,认证不通也无从使用;#270(桌面自带 CLI 缺 @zcode/tui)合并进了 #29,本条是同一"独立 CLI 可用性"版图上的另一块缺口,但根因独立(后端端点缺失 vs 打包缺包),故单开。
你认为的优先级 · Your perceived priority
高 · High(独立 CLI 认证完全不可用)
你使用的 ZCode 版本 / 环境 · ZCode version / environment
- Windows 11 桌面版 v3.7.x(待更新 3.7.7),自带 CLI 0.16.3
- 复现与端点探测均为实测(curl + bundle 反混淆核对)
补充材料 · Additional context
- 相关:#29(P1,非交互执行入口,#270 已并入)、#336(另一独立 bug:agents 目录扫描跳过符号链接)
- 桌面 App 登录端点对照:
https://zcode.z.ai/api/v1/oauth/token(存在于 app.asar 字符串)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with resources/glm/zcode.cjs and the login entry point, then reproduce the POST to /api/v1/oauth/cli/init described in the report. Check the device-flow endpoints and the empty-response handling; done means zcode login completes authentication or reports the HTTP status and URL clearly instead of a JSON parsing error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, authentication, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100