Skip to content

fix: accept current global userinfo shape in PAT login - #4

Closed
darkmore666 wants to merge 1 commit into
Liki4:masterfrom
darkmore666:fix/userinfo-current-shape
Closed

darkmore666 wants to merge 1 commit into
Liki4:masterfrom
darkmore666:fix/userinfo-current-shape

Conversation

@darkmore666

Copy link
Copy Markdown

问题

-region global + 环境 PAT(QODER_PERSONAL_ACCESS_TOKEN)启动时直接失败:

environment PAT authentication: could not fetch user info after exchange

POST /api/v1/jobToken/exchange 本身返回 200,失败的是随后的 GET /api/v1/userinfo 解析。

根因

global 的 /api/v1/userinfo 现在返回新形状:

{
  "id": "...",
  "name": "...",
  "username": "...",
  "avatar": "https://...",
  "organization_id": "...",
  "organization_name": "...",
  "is_privacy_policy_modifiable": false
}

用户 ID 在 id 字段里,而 authUserInfoProfile 只认 uid。于是 profile.UID == "",PAT 登录被判定失败,只能看到一句笼统的 could not fetch user info after exchange。

除 uid 外,同一响应里还有几处字段名变化:avatar(旧 avatar_url)、is_privacy_policy_modifiable(旧 is_data_policy_modifiable),以及 camelCase 的组织字段。

修改

  • authUserInfoProfile 同时接受新旧两种形状:id / user_id / uid,name / username / user_name,avatar_url / avatar,organization_id / orgId / organizationId,以及嵌套的 organization 对象。
  • 新增 normalize(),按官方 CLI 的字段优先级归一化后再交给 applyAuthUserInfoProfile,调用方仍然只处理稳定的 userInfo 字段。
  • PAT 登录失败信息带上真实原因(%w);UID 缺失时单独说明,以后同类形状变化不必再猜。
  • 新增 auth_userinfo_shape_test.go:新形状、旧形状,以及 PAT 登录全流程回归。

验证

  • go test ./... 通过。
  • 真实 global 账号 + 环境 PAT 启动:credentials loaded → listening on 127.0.0.1:8377,GET /v1/models 返回 200,POST /v1/chat/completions 正常返回。
  • 旧形状响应(uid + organization_tags + data_policy_agreed)行为不变。

兼容性

仅放宽解析,不改变既有响应支持范围,不需要配置迁移。

The global /api/v1/userinfo endpoint now returns id/name/username/avatar
and camelCase organization fields instead of uid/organization_tags. PAT
exchange succeeded but the UID lookup failed, aborting startup with
"could not fetch user info after exchange".

Normalize both legacy and current response shapes, mirroring the official
CLI field precedence, and include the underlying userinfo error in the
failure message so future shape changes remain diagnosable.
@darkmore666
darkmore666 force-pushed the fix/userinfo-current-shape branch from abd223d to a56dde6 Compare November 9, 2026 09:57
@darkmore666 darkmore666 closed this by deleting the head repository Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant