larksuite / larksuite/cli

[bug]lark-cli config bind --identity 切换会导致已授权的 user token 失效

Open
#1,274 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug domain/auth
Dominant language
Go
Stars
17.3k
Forks
1.4k
Avg merge
2d 4h
Merged PRs (30d)
105

Description

问题概述

lark-cli config bind --identity <identity> 在切换配置绑定的身份类型后,已通过 auth login 授权成功并缓存的 user token 被清除或不再被识别,导致 lark-cli auth status 中的 user identity 从 ready 瞬间变为 missing。用户需重新走完整授权流程,这在 Hermes Agent 自动化场景下造成严重中断。


环境信息

  • CLI 版本:lark-cli version 1.0.47
  • 操作系统:macOS 26.5
  • 绑定配置路径/.lark-cli/hermes/config.json
  • 应用 IDcli_aa928f5cf938de17
  • Skill 路径~/.hermes/skills/lark-doc~/.hermes/skills/lark-shared

详细现象

操作序列 1:Bot 绑定 + 用户授权成功
lark-cli config bind --source hermes --identity bot-only
# 输出:绑定成功,identity: bot-only

运行授权流程(完整 device flow)后:

lark-cli auth login --no-wait --json --recommend --exclude "docs:secure_label:write_only"
# 获取 device_code 和 verification_url
lark-cli auth login --device-code <code>
# 输出:
#   OK: 授权成功! 用户: 用户xxx (xxx)

此时验证:

lark-cli auth status

输出

{
  "appId": "cli_xxx",
  "defaultAs": "user",
  "identity": "user",
  "identities": {
    "user": {
      "status": "ready",
      "available": true,
      "openId": "xxx",
      "userName": "用户375317",
      "tokenStatus": "valid"
    }
  }
}

操作序列 2:切换 identity 后 token 失效
lark-cli config bind --source hermes --identity user-default

关键输出

⚠️ 你正在从应用身份切换到用户身份 ... 
配置成功!
"message": "已绑定应用 cli_xxx 到 Hermes。请接着在此 Hermes 对话中运行 `lark-cli auth login --recommend`。"

再次运行 auth status

lark-cli auth status

输出

{
  "appId": "cli_aa928f5cf938de17",
  "defaultAs": "bot",
  "identity": "bot",
  "identities": {
    "bot": { "status": "ready" },
    "user": {
      "status": "missing",
      "available": false,
      "message": "User identity: missing (no user logged in)"
    }
  }
}

结果:刚刚授权成功的 user token 消失,openIdtokenStatus 等字段全部清空,用户被强制要求重新登录。


核心问题

  1. config bind --identity 副作用不透明:CLI 未在切换身份前提示“切换将清除现有 token”,也未在切换后说明 token 已被清除。
  2. --identity 的语义不清晰user-defaultbot-only 的区分到底是“默认使用身份”还是“身份绑定策略”,Help 文档未明确。
  3. Agent 自动化流程被阻断:在 Hermes 等 agent 环境中,身份应作为配置持久化,而不是每次绑定都会被重置。

完整复现步骤

  1. lark-cli config bind --source hermes --identity bot-only
  2. 执行完整授权:lark-cli auth login --scope "docs:document:write_only docx:document:write_only"(或走 --no-wait device flow)
  3. 确认 lark-cli auth statususer 状态为 readytokenStatusvalid
  4. 执行 lark-cli config bind --source hermes --identity user-default
  5. 再次运行 lark-cli auth status
  6. 观察user 状态变为 missingopenId 字段消失

期望行为

  • config bind --identity 不应静默清除已存在的 user token
  • 若切换确实需要重新授权,应在输出中明确警告:

    "Changing identity from 'bot-only' to 'user-default' will invalidate the current user token. Please run lark-cli auth login to re-authorize."

  • 或提供 --preserve-token 参数,避免强制清除
  • config bind --help 应明确列出 --identity 的合法取值及其副作用说明

影响范围

  • 任何需要 bot 与 user 双身份的 Agent 工作流
  • 文档创建 (docs +create) 后切换到 user 身份写入 (docs +update)
  • 日历、任务、消息等跨身份操作场景

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the documented sequence with config bind --identity, auth login, and auth status, using /.lark-cli/hermes/config.json as the configuration path. Trace how identity binding affects the cached user token, then verify that switching identities preserves the token or clearly reports any required reauthorization; also review the config bind --help behavior for identity values and side effects.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
authentication, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.