yida-login
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese宜搭登录态管理技能
Yida Login State Management Skill
概述
Overview
本技能提供宜搭平台的登录态管理能力,支持 Cookie 持久化和自动验证,首次使用需扫码登录,后续自动复用 Cookie。
This skill provides login state management capabilities for the Yida platform, supporting cookie persistence and automatic verification. A QR code login is required for the first use, and cookies will be reused automatically in subsequent uses.
何时使用
When to Use
当以下场景发生时使用此技能:
- 首次使用宜搭技能,需要扫码登录
- Cookie 过期或失效,需要重新登录
- 其他技能调用时提示登录态异常
- 用户要求手动执行登录
Use this skill in the following scenarios:
- First-time use of Yida skills, requiring QR code login
- Cookies expired or invalid, requiring re-login
- Login state exception prompts when calling other skills
- User requests manual login execution
使用示例
Usage Examples
示例 1:触发登录
Example 1: Trigger Login
场景:手动触发扫码登录
命令:
bash
python3 .claude/skills/yida-login/scripts/login.py输出:
json
{"csrf_token":"b2a5d192-xxx","corp_id":"dingxxx","user_id":"1955225xxx","base_url":"https://abcd.aliwork.com"}Scenario: Manually trigger QR code login
Command:
bash
python3 .claude/skills/yida-login/scripts/login.pyOutput:
json
{"csrf_token":"b2a5d192-xxx","corp_id":"dingxxx","user_id":"1955225xxx","base_url":"https://abcd.aliwork.com"}示例 2:刷新 CSRF Token
Example 2: Refresh CSRF Token
场景:CSRF Token 失效但 Cookie 有效
命令:
bash
python3 .claude/skills/yida-login/scripts/login.py --refresh-csrfScenario: CSRF Token is invalid but cookies are valid
Command:
bash
python3 .claude/skills/yida-login/scripts/login.py --refresh-csrf使用方式
Usage Method
bash
python3 .claude/skills/yida-login/scripts/login.py无需任何参数,登录地址从项目根目录的 中读取( 字段),登录后可能跳转到 等域名。
config.jsonloginUrlabcd.aliwork.com输出:登录成功后,将 、(跳转后的实际域名)和 Cookie 信息以 JSON 格式输出到 stdout,同时 Cookie 持久化到项目根目录的 。
csrf_tokenbase_url.cache/cookies.json⚠️ 重要:取自登录成功后浏览器实际跳转到的域名,而非base_url中配置的config.json或loginUrl。例如,即使defaultBaseUrl配置为loginUrl,如果你的账号所属组织对应的是https://www.aliwork.com,平台会自动跳转,最终abcd.aliwork.com将是base_url。后续所有 API 请求(包括https://abcd.aliwork.com发布)都会使用这个yida-publish。如需发布到特定域名,请确保base_url中的config.json指向该域名对应的组织,并且你的账号属于该组织。loginUrl
项目根目录通过向上查找或config.json目录来定位。.git
bash
python3 .claude/skills/yida-login/scripts/login.pyNo parameters are required. The login address is read from the field in the file in the project root directory. After login, it may redirect to domains such as .
loginUrlconfig.jsonabcd.aliwork.comOutput: After successful login, , (the actual domain after redirection) and cookie information will be output to stdout in JSON format. Meanwhile, cookies will be persisted to in the project root directory.
csrf_tokenbase_url.cache/cookies.json⚠️ Important:is obtained from the actual domain the browser redirects to after login, not thebase_urlorloginUrlconfigured indefaultBaseUrl. For example, even ifconfig.jsonis configured asloginUrl, if your account's organization corresponds tohttps://www.aliwork.com, the platform will automatically redirect, and the finalabcd.aliwork.comwill bebase_url. All subsequent API requests (includinghttps://abcd.aliwork.comreleases) will use thisyida-publish. To publish to a specific domain, ensure that thebase_urlinloginUrlpoints to the domain corresponding to that organization, and your account belongs to that organization.config.json
The project root directory is located by searching upward for theorconfig.jsondirectory..git
工作流程
Workflow
- 检查本地是否存在 缓存(包含 Cookie 和
.cache/cookies.json)base_url - 若存在,直接从 Cookie 中提取 (
csrf_token)、tianshu_csrf_token和corp_id(user_id),无需访问任何页面tianshu_corp_user - 若 Cookie 中无 ,视为失效,打开有头浏览器让用户扫码登录
tianshu_csrf_token - 登录成功后直接从 Cookie 中提取所需信息,保存 Cookie 和 (从登录后实际跳转的 URL 获取)
base_url
- Check if the cache (containing cookies and
.cache/cookies.json) exists locallybase_url - If it exists, directly extract (
csrf_token),tianshu_csrf_tokenandcorp_id(user_id) from the cookies without accessing any pagestianshu_corp_user - If is not present in the cookies, it is considered invalid, and a headed browser will be opened for the user to scan the QR code to log in
tianshu_csrf_token - After successful login, extract the required information directly from the cookies, and save the cookies and (obtained from the actual redirected URL after login)
base_url
前置依赖
Prerequisites
- Python 3.12+
- playwright()
pip install playwright && playwright install chromium
- Python 3.12+
- playwright()
pip install playwright && playwright install chromium
文件结构
File Structure
yida-login/
├── SKILL.md # 本文档
└── scripts/
└── login.py # 登录脚本
项目根目录/
├── config.json # 全局配置(loginUrl、defaultBaseUrl)
└── .cache/
└── cookies.json # 登录态缓存(运行时自动生成,含 Cookie + base_url)yida-login/
├── SKILL.md # This document
└── scripts/
└── login.py # Login script
Project Root Directory/
├── config.json # Global configuration (loginUrl, defaultBaseUrl)
└── .cache/
└── cookies.json # Login state cache (automatically generated at runtime, contains cookies + base_url)输出格式
Output Format
脚本成功执行后,最后一行输出 JSON:
json
{
"csrf_token": "b2a5d192-db90-484c-880f-9b48edd396d5",
"corp_id": "ding9a0954b4f9d9d40ef5bf40eda33b7ba0",
"user_id": "19552253733782",
"base_url": "https://abcd.aliwork.com",
"cookies": [...]
}从 Cookiecsrf_token的 value 中提取;tianshu_csrf_token和corp_id从 Cookieuser_id的 value 中提取,格式为tianshu_corp_user,按最后一个{corpId}_{userId}分隔。_
是登录后浏览器实际跳转到的域名(如base_url),可能与https://abcd.aliwork.com中的config.json不同。其他脚本应使用此值作为 API 请求的基础地址,而非硬编码域名。loginUrl
其他脚本可通过管道接收并解析 stdout 最后一行获取登录态信息。
After the script is successfully executed, the last line outputs JSON:
json
{
"csrf_token": "b2a5d192-db90-484c-880f-9b48edd396d5",
"corp_id": "ding9a0954b4f9d9d40ef5bf40eda33b7ba0",
"user_id": "19552253733782",
"base_url": "https://abcd.aliwork.com",
"cookies": [...]
}is extracted from the value of the cookiecsrf_token;tianshu_csrf_tokenandcorp_idare extracted from the value of the cookieuser_id, which is in the formattianshu_corp_user, separated by the last{corpId}_{userId}._
is the actual domain the browser redirects to after login (e.g.,base_url), which may differ from thehttps://abcd.aliwork.cominloginUrl. Other scripts should use this value as the base address for API requests instead of hardcoding the domain.config.json
Other scripts can receive and parse the last line of stdout via a pipe to obtain login state information.
缓存格式
Cache Format
.cache/cookies.jsonjson
{
"cookies": [...],
"base_url": "https://abcd.aliwork.com"
}csrf_tokencorp_iduser_idtianshu_csrf_tokentianshu_corp_userThe format of the file (compatible with the old pure cookie array):
.cache/cookies.jsonjson
{
"cookies": [...],
"base_url": "https://abcd.aliwork.com"
}csrf_tokencorp_iduser_idtianshu_csrf_tokentianshu_corp_user全局配置
Global Configuration
所有脚本( 及各 JS 脚本)从项目根目录的 读取配置,不再硬编码 URL:
login.pyconfig.jsonjson
{
"loginUrl": "https://www.aliwork.com/workPlatform",
"defaultBaseUrl": "https://www.aliwork.com"
}| 字段 | 说明 |
|---|---|
| 扫码登录页面地址(登录成功后平台可能自动跳转到其他域名) |
| API 请求的默认基础地址(仅当 |
All scripts ( and various JS scripts) read configurations from the file in the project root directory, and no longer hardcode URLs:
login.pyconfig.jsonjson
{
"loginUrl": "https://www.aliwork.com/workPlatform",
"defaultBaseUrl": "https://www.aliwork.com"
}| Field | Description |
|---|---|
| QR code login page address (the platform may automatically redirect to another domain after successful login) |
| Default base address for API requests (only used as a fallback when |
错误处理机制
Error Handling Mechanism
各 skill 脚本通过解析接口响应体的 字段来判断登录态异常,并自动调用本技能处理:
errorCode| errorCode | 含义 | 处理方式 |
|---|---|---|
| csrf 校验失败(csrf_token 过期) | 调用 |
| 登录状态已过期(Cookie 失效) | 调用 |
注意:错误判断基于响应体 JSON 的字段,而非 HTTP 状态码。errorCode
Each skill script determines login state exceptions by parsing the field in the interface response body, and automatically calls this skill for processing:
errorCode| errorCode | Meaning | Handling Method |
|---|---|---|
| CSRF verification failed (csrf_token expired) | Call |
| Login state has expired (cookies invalid) | Call |
Note: Error judgment is based on thefield in the response body JSON, not the HTTP status code.errorCode
退出登录
Logout
清空本地 Cookie 缓存文件内容即可完成退出,下次调用任意技能时将自动触发重新扫码登录:
bash
echo -n "" > .cache/cookies.json适用场景:
- 需要切换账号或切换组织
- Cookie 失效且无法自动刷新
- 用户主动要求退出登录
注意:Cookie 缓存文件位于项目根目录(含或README.md的目录)的.git目录下。退出登录不影响已部署的页面和已保存的数据。.cache/
Clear the content of the local cookie cache file to complete logout. The next time any skill is called, it will automatically trigger re-login via QR code:
bash
echo -n "" > .cache/cookies.jsonApplicable Scenarios:
- Need to switch accounts or organizations
- Cookies are invalid and cannot be refreshed automatically
- User actively requests to log out
Note: The cookie cache file is located in thedirectory of the project root directory (the directory containing.cache/orREADME.md). Logging out does not affect deployed pages or saved data..git
与其他技能配合
Coordination with Other Skills
- 退出登录:需要切换账号或 Cookie 失效时,执行上方「退出登录」命令后重新运行任意技能即可触发扫码登录
- :发布时自动调用本技能获取登录态
yida-publish - 、
yida-create-app、yida-create-page:通过管道将本技能输出传入yida-create-form-page
- Logout: When you need to switch accounts or cookies are invalid, execute the above "Logout" command and then re-run any skill to trigger QR code login
- : Automatically calls this skill to obtain login state during publishing
yida-publish - ,
yida-create-app,yida-create-page: Pass the output of this skill via a pipeyida-create-form-page