auth
contract-cli 登录与身份切换技能:初始化 dev profile、执行 user OAuth 登录、录入 bot 的 app_id/app_secret 并立即兑换 tenant_access_token、查看状态、切换默认身份、排查本地 config/secrets 持久化问题。当用户需要 `contract-cli config add`、`contract-cli auth login --as user|bot`、`contract-cli auth status/logout/use` 或排查登录异常时触发。
How do I install this agent skill?
npx skills add https://github.com/qfeius/contract-cli --skill authIs this agent skill safe to install?
- Gen Agent Trust Hubpass
This skill provides instructions for managing authentication and identity switching for the contract-cli tool. It covers initializing configurations, performing OAuth logins for users, and setting up bot credentials. It follows security best practices by recommending environment variables for secrets and prohibiting the disclosure of tokens in logs.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
contract-cli Auth
本技能指导你如何在本仓库中使用 contract-cli 的登录与身份切换能力,并保持和当前实现一致。
适用范围
- 首次初始化本地
profile - 以
user身份走 OAuth 授权码 + PKCE 登录 - 以
bot身份录入app_id/app_secret - 查看或清理本地身份状态
- 切换默认业务身份
- 排查
config.json和secrets.json的本地持久化问题
实现来源
- internal/cli/app.go
- internal/cli/auth_provider.go
- internal/config/store.go
- internal/config/secrets.go
配置初始化
首次使用前,必须先执行:
contract-cli config add --env dev
当前实现只内置 dev 环境,默认 profile 名为 contract-group。该命令会:
- 发现 well-known 元数据
- 保存 MCP server / resource / OAuth server 配置
- 将
default_identity初始化为user
身份模型
同一个 profile 下维护两种身份:
| 身份 | 命令 | 本地存储 | 当前实现 |
|---|---|---|---|
user | contract-cli auth login --as user | profiles.<name>.identities.user.token | 已实现 OAuth 登录 |
bot | contract-cli auth login --as bot | profiles.<name>.identities.bot + secrets.json | 已实现凭据录入和 tenant_access_token 兑换 |
额外还有一个默认身份指针:
profiles.<name>.default_identity- 由
contract-cli auth use --as user|bot修改 auth login --as ...成功后也会自动切换到对应身份
快速流程
user 登录
contract-cli config add --env dev
contract-cli auth login --as user
contract-cli auth status --as user
行为约束:
user登录会自动注册client_id- 使用授权码模式 + PKCE
- 会启动本地回调服务,回调地址来自 profile 中的
redirect_url - 默认自动打开浏览器;如需仅打印链接,使用
--no-open-browser - 登录成功后写入
identities.user.token
bot 登录
contract-cli auth login --as bot --app-id "<app_id>" --app-secret "<app_secret>"
contract-cli auth status --as bot
也可以通过环境变量提供凭据:
export CONTRACT_CLI_BOT_APP_ID="<app_id>"
export CONTRACT_CLI_BOT_APP_SECRET="<app_secret>"
contract-cli auth login --as bot
运行时也兼容旧变量 DEMOCLI_BOT_APP_ID / DEMOCLI_BOT_APP_SECRET,但后续新增配置统一使用 CONTRACT_CLI_*。
凭据优先级固定为:
- 命令行参数
- 环境变量
- 本地已保存凭据
行为约束:
bot登录会先保存app_id/app_secret,再调用tenant_access_token/internal兑换 tokenapp_secret不写入config.json- token 成功后写入
identities.bot.token - token 兑换失败时,会保留新凭据,但不会切换默认身份到
bot - 登录成功后会切换
default_identity=bot
状态、退出与切换
查看状态
contract-cli auth status --as user
contract-cli auth status --as bot
规则:
- 不传
--as时,auth status默认查看user user显示authorized或unauthorizedbot显示authorized、expired、configured或unconfiguredbot状态会显示Token Endpoint、Token Protocol: tenant_access_token/internal和过期时间(若有)
退出登录
contract-cli auth logout --as user
contract-cli auth logout --as bot
规则:
logout --as user只清理user.tokenlogout --as bot只清理bot.token,保留app_id/app_secret和对应 secret- 不传
--as时,auth logout默认处理user
切换默认身份
contract-cli auth use --as user
contract-cli auth use --as bot
规则:
- 该命令只修改
default_identity - 不会重新登录
- 不会校验目标身份一定已拿到 token
本地文件
默认路径如下,若设置了 CONTRACT_CLI_CONFIG_DIR,则改为该目录:
~/.contract-cli/config.json~/.contract-cli/secrets.json
运行时也兼容旧的 DEMOCLI_CONFIG_DIR 以及历史默认目录 ~/.democli,用于平滑读取已有本地登录态。
存储约束:
config.json保存 profile、identity 元数据和 tokensecrets.json只保存 bot 的app_secretuser.token与bot.token分离存储,不共享- 旧版平铺 OAuth 字段会自动迁移到
identities.user
安全规则
- 禁止在终端或文档中明文输出
app_secret、access_token、refresh_token - 不要把
bot登出描述成“删除凭据”,当前实现只清 token、不删app_id/app_secret - 不要让用户误以为
default_identity会影响auth status或auth logout的默认目标,这两个命令未传--as时仍按user - 涉及写入、清理本地凭据时,先确认是在当前 profile 上操作
故障排查
user identity is not configured:先执行contract-cli config add --env dev- 浏览器未自动打开:改用
--no-open-browser,手动访问输出的授权链接 - 回调超时:检查
redirect_url对应端口是否可监听,必要时调大--timeout - bot 凭据不完整:补齐
--app-id/--app-secret或设置CONTRACT_CLI_BOT_APP_ID/CONTRACT_CLI_BOT_APP_SECRET - bot 登录提示缺少
bot_token_endpoint:说明 profile 过旧,重跑contract-cli config add --env dev --name <profile> - bot 状态显示
expired:重新执行contract-cli auth login --as bot
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/qfeius/contract-cli/auth">View auth on skillZs</a>