feishu-user-auth
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFeishu User Auth
Feishu User Auth
这个 skill 只负责两件事:
- 发起飞书用户授权
- 尽可能复用已有 token,避免重复弹授权页
This skill only handles two things:
- Initiate Feishu user authorization
- Reuse existing tokens as much as possible to avoid repeated authorization pop-ups
何时使用
When to Use
当用户有这些诉求时直接用:
- 给飞书应用做用户授权
- 排查为什么总是反复弹授权窗
- 想知道本地是否已经授权过某个用户
- 想补一批新的 scopes,但不想把旧授权丢掉
- 想删除某个用户的本地 token 重新授权
Use this skill directly when users have the following needs:
- Implement user authorization for Feishu applications
- Troubleshoot why authorization pop-ups keep appearing repeatedly
- Check if a user has already authorized locally
- Want to add new scopes without losing old authorizations
- Want to delete a user's local token and re-authorize
存储位置
Storage Location
默认情况下,本 skill 会把 token 存到用户目录下:
~/.feishu-auth/tokens/<appId>.json
如果你在 里显式配置了 ,就会改为:
config.jsonstoreDir<storeDir>/tokens/<appId>.json
storeDir~/.feishu-auth旧版如果还把 token 放在 legacy 目录下,脚本会从这两种位置尝试迁移:
<legacyStoreDir>/tokens/<appId>.json<legacyStoreDir>/<appId>__<openId>.json
脚本会默认把这个旧目录当作迁移来源,在新目录为空时自动尝试迁移。
By default, this skill stores tokens in the user directory:
~/.feishu-auth/tokens/<appId>.json
If you explicitly configure in , the path will be changed to:
storeDirconfig.json<storeDir>/tokens/<appId>.json
storeDir~/.feishu-authFor older versions where tokens are stored in the legacy directory, the script will attempt to migrate from these two locations:
<legacyStoreDir>/tokens/<appId>.json<legacyStoreDir>/<appId>__<openId>.json
The script will use this old directory as the default migration source and automatically attempt migration when the new directory is empty.
前置配置
Pre-configuration
先找到安装后的 skill 目录,再维护其中的 。
config.json常见安装位置:
- 项目内安装:
./.agents/skills/feishu-user-auth/config.json - 全局安装():
npx skills add ... -g~/.agents/skills/feishu-user-auth/config.json
如果你不想改 skill 目录,也可以自己准备一个配置文件,后面通过 传入。
--config格式如下:
json
{
"appId": "cli_xxx",
"appSecret": "replace-with-app-secret",
"brand": "feishu"
}说明:
- 、
appId必填appSecret - 可选,默认
brandfeishu - 可选;如果不填,默认就是
storeDir~/.feishu-auth - 如果显式填写 ,可以写绝对路径,也可以写
storeDir~/.feishu-auth - 可选,默认指向 skill 自己的
legacyStoreDirstate/
这套脚本不再依赖系统里的 、、、 环境变量。
FEISHU_APP_IDFEISHU_APP_SECRETFEISHU_BRANDFEISHU_AUTH_*First, find the installed skill directory, then maintain the file within it.
config.jsonCommon installation locations:
- Project-local installation:
./.agents/skills/feishu-user-auth/config.json - Global installation ():
npx skills add ... -g~/.agents/skills/feishu-user-auth/config.json
If you don't want to modify the skill directory, you can prepare your own configuration file and pass it in via later.
--configFormat as follows:
json
{
"appId": "cli_xxx",
"appSecret": "replace-with-app-secret",
"brand": "feishu"
}Notes:
- and
appIdare requiredappSecret - is optional, default is
brandfeishu - is optional; if not specified, the default is
storeDir~/.feishu-auth - If is explicitly filled in, it can be an absolute path or
storeDir~/.feishu-auth - is optional, default points to the skill's own
legacyStoreDirdirectorystate/
This set of scripts no longer depends on environment variables like , , , and in the system.
FEISHU_APP_IDFEISHU_APP_SECRETFEISHU_BRANDFEISHU_AUTH_*执行方式
Execution Methods
安装后,默认不会自动把 加进 PATH。
feishu-auth最稳妥的调用方式是直接执行安装目录里的 bin:
bash
./.agents/skills/feishu-user-auth/bin/feishu-auth.js auth如果你是全局安装,可以从任意目录执行:
bash
~/.agents/skills/feishu-user-auth/bin/feishu-auth.js auth如果你想直接用 命令名,可以自己加一个链接:
feishu-authbash
mkdir -p ~/.local/bin
ln -sf ~/.agents/skills/feishu-user-auth/bin/feishu-auth.js ~/.local/bin/feishu-auth然后确保 在 PATH 中,就可以直接执行:
~/.local/binbash
feishu-auth auth可用命令:
bash
<skill-dir>/bin/feishu-auth.js auth [--batch-size 60] [--open-id ou_xxx]
<skill-dir>/bin/feishu-auth.js user-auth [--batch-size 60] [--open-id ou_xxx]
<skill-dir>/bin/feishu-auth.js auth --scope "scope1 scope2"
<skill-dir>/bin/feishu-auth.js refresh-token [--open-id ou_xxx]
<skill-dir>/bin/feishu-auth.js refresh-token [--open-id ou_xxx] --force
<skill-dir>/bin/feishu-auth.js show-token
<skill-dir>/bin/feishu-auth.js show-token --open-id ou_xxx
<skill-dir>/bin/feishu-auth.js remove-token --open-id ou_xxx
<skill-dir>/bin/feishu-auth.js system-token
<skill-dir>/bin/feishu-auth.js system-auth
<skill-dir>/bin/feishu-auth.js --config /path/to/config.json auth
<skill-dir>/bin/feishu-auth.js --help如果你是在仓库里本地开发,这时才适合在仓库根目录执行源码入口:
bash
node skills/feishu-user-auth/scripts/run-auth.js authAfter installation, is not automatically added to the PATH by default.
feishu-authThe most reliable way to call it is to directly execute the bin file in the installation directory:
bash
./.agents/skills/feishu-user-auth/bin/feishu-auth.js authIf installed globally, you can execute it from any directory:
bash
~/.agents/skills/feishu-user-auth/bin/feishu-auth.js authIf you want to use the command name directly, you can create a link yourself:
feishu-authbash
mkdir -p ~/.local/bin
ln -sf ~/.agents/skills/feishu-user-auth/bin/feishu-auth.js ~/.local/bin/feishu-authThen ensure is in your PATH, and you can execute directly:
~/.local/binbash
feishu-auth authAvailable commands:
bash
<skill-dir>/bin/feishu-auth.js auth [--batch-size 60] [--open-id ou_xxx]
<skill-dir>/bin/feishu-auth.js user-auth [--batch-size 60] [--open-id ou_xxx]
<skill-dir>/bin/feishu-auth.js auth --scope "scope1 scope2"
<skill-dir>/bin/feishu-auth.js refresh-token [--open-id ou_xxx]
<skill-dir>/bin/feishu-auth.js refresh-token [--open-id ou_xxx] --force
<skill-dir>/bin/feishu-auth.js show-token
<skill-dir>/bin/feishu-auth.js show-token --open-id ou_xxx
<skill-dir>/bin/feishu-auth.js remove-token --open-id ou_xxx
<skill-dir>/bin/feishu-auth.js system-token
<skill-dir>/bin/feishu-auth.js system-auth
<skill-dir>/bin/feishu-auth.js --config /path/to/config.json auth
<skill-dir>/bin/feishu-auth.js --helpIf you are developing locally in a repository, you can execute the source code entry in the repository root directory:
bash
node skills/feishu-user-auth/scripts/run-auth.js auth工作规则
Working Rules
按这个顺序做:
- 优先复用已保存 token
- 如果未指定 ,自动挑选最适合复用的用户记录
--open-id - 如果应用 scopes 比本地已授权 scopes 多,只补缺失部分
- 分批授权后把 scopes 做并集保存,不要覆盖旧批次
Follow this sequence:
- Prioritize reusing saved tokens
- If is not specified, automatically select the most suitable user record to reuse
--open-id - If the application's scopes are more than the locally authorized scopes, only supplement the missing parts
- After batch authorization, save the union of scopes and do not overwrite old batches
排障重点
Troubleshooting Key Points
如果用户说“明明授权过还是弹窗”,先检查这几项:
- 是否走了这个 skill 的脚本,而不是直接跑了别的脚本
- 里的
config.json是否和旧 token 对应的是同一个 appappId - 当前 里是否确实有该 app 的记录
storeDir/tokens/ - 本次要的 scopes 是否超出了历史已授权范围
- token 是否已经 ,或者只剩
expiredneeds_refresh
If users say "It still pops up even though I've authorized before", check these items first:
- Whether the script of this skill is used, instead of other scripts
- Whether the in
appIdcorresponds to the same app as the old tokenconfig.json - Whether there is indeed a record for the app in the current
storeDir/tokens/ - Whether the scopes required this time exceed the historically authorized scope
- Whether the token has or is in
expiredstatusneeds_refresh
输出要求
Output Requirements
告诉用户这些关键信息:
- 复用了哪个
open_id - 本次是否真的需要重新授权
- 如果需要,是因为缺哪些 scopes
- token 最终落在哪个 文件里
storeDir/tokens/<appId>.json
Inform users of these key pieces of information:
- Which was reused
open_id - Whether re-authorization is actually needed this time
- If needed, which scopes are missing
- The final location of the token in the file
storeDir/tokens/<appId>.json