Chanjing Credentials Guard
When to Run
- 1. When user asks to configure/get Chanjing keys (AK/SK): use this skill to guide local setup.
- When credentials are missing/invalid before a Chanjing API call: use this skill to recover local config.
This skill is a local credential guide, not a runtime dependency for other skills.
It does not require bundled helper scripts to be present.
Execution Flow
CODEBLOCK0
Credential Storage
AK/SK and Token are read from the same local config file.
- - Path:
~/.chanjing/credentials.json (overridable by env CHANJING_CONFIG_DIR) - Format:
CODEBLOCK1
INLINECODE2 is a Unix timestamp. Token is valid for about 24 hours; refresh 5 minutes before expiry.
When AK/SK Is Missing
When local app_id or secret_key is missing:
- 1. Open login page: open
https://www.chanjing.cc/openapi/login in the default browser. - Require local setup after the user obtains keys:
- User updates local
credentials.json file.
- 3. Do not request secrets in chat:
- Never ask user to paste AK/SK in conversation.
- Never echo or store AK/SK in chat summaries.
- 4. After setting:
- Ask user to run status check and then proceed to target action.
Manual update example:
CODEBLOCK2
Guide When User Wants to Generate Keys
When the user clearly wants to generate chanjing keys, get keys, or configure AK/SK, follow this flow:
Step 1: Check if already configured
Check if local AK/SK already exists (read ~/.chanjing/credentials.json for non-empty app_id and secret_key).
Step 2: Branch on result
- - If already configured: ask whether user wants to overwrite local config.
- If yes, run guide steps.
- If no, stop.
- - If not configured: Run the “Guide steps” below directly.
Guide steps (when not configured or user confirmed re-apply)
- 1. Open
https://www.chanjing.cc/openapi/login in browser. - Explain the page flow clearly:
- New users are registered automatically and the current page will display
App ID and
Secret Key with copy buttons.
- Existing users may be redirected to the console; tell them to open the left-side
API 密钥 page to view or reset keys.
- 3. Ask user to configure local file
~/.chanjing/credentials.json (or $CHANJING_CONFIG_DIR/credentials.json) with app_id and secret_key. - Secret handling rule:
- Do not ask user to paste AK/SK in chat.
- If user shares secret in chat anyway, remind them to rotate keys and continue with local-command-only flow.
- 5. After setting:
- Re-open the local file to confirm non-empty
app_id and
secret_key.
- Then proceed to target Chanjing action.
Token API (see chanjing-openapi.yaml)
CODEBLOCK3
Request body:
CODEBLOCK4
Response (success code: 0):
CODEBLOCK5
- -
expire_in: Unix timestamp for token expiry - If
code !== 0, AK/SK is invalid or the request failed
Validation Logic
- 1. AK/SK: Read from config (path/format above); ensure
app_id and secret_key are non-empty. - Token: Ensure
access_token exists and expire_in > current_time + 300 (refresh 5 minutes early). - Token refresh: Call the API above and write returned
access_token and expire_in back to the file.
Security Boundary
- - This skill only handles local credential guidance.
- It does not require install hooks or elevated/system-wide privileges.
- It should not automatically execute unrelated skills.
- It should not accept AK/SK via chat content.
Packaging Note
- - This skill can work as a documentation-only guide.
- If a package variant includes helper scripts, they are optional convenience utilities, not required for core behavior.
With Other Skills
- - Other Chanjing skills may use the same local config path/format, but should keep their own runtime auth logic.
- Guard can be used as an optional setup helper when users explicitly ask for credential guidance.
Reference
- - reference.md: API and storage format details
- chanjing-openapi.yaml:
/access_token, dto.OpenAccessTokenReq, INLINECODE30
Chanjing 凭证守护
何时运行
- 1. 当用户要求配置/获取 Chanjing 密钥(AK/SK)时:使用此技能指导本地配置。
- 当在调用 Chanjing API 前凭证缺失或无效时:使用此技能恢复本地配置。
此技能是一个本地凭证指南,并非其他技能的运行时依赖项。
它不需要附带辅助脚本。
执行流程
- 1. 检查本地 AK/SK 是否存在
└─ 否 → 在浏览器中打开登录页面 URL → 要求用户配置本地文件
└─ 是 → 继续
- 2. 检查本地 Token 是否存在且未过期
└─ 否 → 调用 API 请求/刷新 Token → 保存到本地文件
└─ 是 → 继续
- 3. 提示用户继续目标操作
凭证存储
AK/SK 和 Token 从同一个本地配置文件中读取。
- - 路径:~/.chanjing/credentials.json(可通过环境变量 CHANJINGCONFIGDIR 覆盖)
- 格式:
json
{
app_id: 您的访问密钥,
secret_key: 您的秘密密钥,
access_token: 可选,自动生成,
expire_in: 1721289220
}
expire_in 是一个 Unix 时间戳。Token 有效期约为 24 小时;在过期前 5 分钟刷新。
当 AK/SK 缺失时
当本地 appid 或 secretkey 缺失时:
- 1. 打开登录页面:在默认浏览器中打开 https://www.chanjing.cc/openapi/login。
- 在用户获取密钥后要求本地配置:
- 用户更新本地的 credentials.json 文件。
- 3. 不要在聊天中索取密钥:
- 切勿要求用户在对话中粘贴 AK/SK。
- 切勿在聊天摘要中回显或存储 AK/SK。
- 4. 配置完成后:
- 要求用户运行状态检查,然后继续目标操作。
手动更新示例:
json
{
appid: app_id>,
secretkey: secret_key>
}
当用户想要生成密钥时的指南
当用户明确想要生成 Chanjing 密钥、获取密钥或配置 AK/SK 时,请遵循以下流程:
步骤 1:检查是否已配置
检查本地 AK/SK 是否已存在(读取 ~/.chanjing/credentials.json 中非空的 appid 和 secretkey)。
步骤 2:根据结果分支处理
- 如果是,运行指南步骤。
- 如果否,停止。
指南步骤(未配置或用户确认重新配置时)
- 1. 在浏览器中打开 https://www.chanjing.cc/openapi/login。
- 清晰解释页面流程:
- 新用户会自动注册,当前页面会显示带有复制按钮的 App ID 和 Secret Key。
- 现有用户可能会被重定向到控制台;告知他们打开左侧的
API 密钥 页面以查看或重置密钥。
- 3. 要求用户配置本地文件 ~/.chanjing/credentials.json(或 $CHANJINGCONFIGDIR/credentials.json),填入 appid 和 secretkey。
- 密钥处理规则:
- 不要要求用户在聊天中粘贴 AK/SK。
- 如果用户仍然在聊天中分享了密钥,提醒他们轮换密钥,并继续仅使用本地命令的流程。
- 5. 配置完成后:
- 重新打开本地文件,确认 app
id 和 secretkey 非空。
- 然后继续执行目标 Chanjing 操作。
Token API(参见 chanjing-openapi.yaml)
http
POST https://open-api.chanjing.cc/open/v1/access_token
Content-Type: application/json
请求体:
json
{
appid: {{appid}},
secretkey: {{secretkey}}
}
响应(成功 code: 0):
json
{
code: 0,
msg: success,
data: {
access_token: xxx,
expire_in: 1721289220
}
}
- - expire_in:Token 过期的 Unix 时间戳
- 如果 code !== 0,则 AK/SK 无效或请求失败
验证逻辑
- 1. AK/SK:从配置文件中读取(路径/格式如上);确保 appid 和 secretkey 非空。
- Token:确保 accesstoken 存在且 expirein > currenttime + 300(提前 5 分钟刷新)。
- Token 刷新:调用上述 API,并将返回的 accesstoken 和 expire_in 写回文件。
安全边界
- - 此技能仅处理本地凭证指导。
- 它不需要安装钩子或提升/系统级权限。
- 它不应自动执行不相关的技能。
- 它不应通过聊天内容接受 AK/SK。
打包说明
- - 此技能可以作为纯文档指南使用。
- 如果某个打包变体包含辅助脚本,它们是可选的便利工具,并非核心行为所必需。
与其他技能的协作
- - 其他 Chanjing 技能可能使用相同的本地配置路径/格式,但应保持自己的运行时认证逻辑。
- 当用户明确要求凭证指导时,Guard 可作为可选的配置助手使用。
参考
- - reference.md:API 和存储格式详情
- chanjing-openapi.yaml:/accesstoken、dto.OpenAccessTokenReq、dto.OpenAccessTokenResp