starchild-auth
БесплатноБез исполняемых скриптовНе проверенStarchild Auth SDK: add OAuth login to any web app with one SDK. Use when integrating Starchild login into a project (e.g. add Starchild sign-in to my React…
от Starchild-ai-agent★ 34 звезды на GitHubОб этом скилле
🔑 Starchild Auth SDK — 完整开发指南
Integrate Starchild OAuth login into any web application. The SDK handles OAuth popup flow, token refresh, unified StarchildAuthError, namespaced helpers (auth.chat / auth.credit …), and 60+ API methods for full Agent access.
版本策略
| 产物 | 当前版本 | 何时 bump |
|---|---|---|
npm starchild-auth-sdk |
0.4.1 | 代码 / 公开 API 变更 |
本 Skill starchild-auth |
1.11.1 | 集成指南 / 场景文档变更(可与 package 独立) |
两套 semver 互不绑定:只改文档可只升 skill;只改实现必须升 package(skill 通常同步升 minor/patch 说明新能力)。
架构概览
第三方网站 (your-app.com)
│
├─ StarchildAuth SDK (starchild-auth-sdk)
│ ├─ auth.login() → 弹出 starchild-web 授权页面
│ ├─ auth.logout() → go-api POST /v1/oauth/logout
│ ├─ auth.bindAccount() → 跳转主站 Linked accounts 绑定正式账号
│ └─ token refresh → go-api POST /v1/oauth/refresh
│
├─ API 调用 (chat scope)
│ ├─ chat/stream → clawd (SSE 流式响应)
│ ├─ /api/clawd/* → ai-agent (线程/消息)
│ ├─ /api/cloud/* → ai-agent (容器管理)
│ └─ WebSocket → clawd (文件同步/终端/指标)
│
├─ Credits API (credit:read / credit:write)
│ └─ https://credit.iamstarchild.com
│ ├─ GET /api/credits|charges|topups|usage/daily|pending|tx/{hash}
│ ├─ POST /api/stripe/create-session | gift-cards/redeem | points/exchange
│ ├─ GET/POST /api/kyc/* | /api/referral/* | /api/migration/reward/*
│ └─ GET /api/public/users/{id}/woo-bonus
│
└─ 用户信息
└─ /v1/oauth/userinfo → ai-agent
应用注册与审核
注册流程
- 在 iamstarchild.com → More → OAuth Apps → Create App
- 填写信息:
- Name (必填): 应用名称
- Allowed Origin (必填): 第三方应用自己的页面 Origin(不是 starchild-web)。例:生产
https://your-app.com;本地http://localhost:5173/http://localhost:3333。只允许 origin(scheme://host[:port],无路径/query/hash);非 localhost 必须https://。可配多个。不要把http://localhost:6066当成第三方 origin——6066 是主站 web 本地端口,已在服务端静态 CORS 中放行。 - Scopes: 勾选需要的权限
- System Prompt (可选): 自定义 Agent 行为
- 仅选
profile→ 自动通过,立即获得 Client ID - 选了
chat/credit:read/credit:write→ 进入管理员审核,审核通过后才生成 Client ID
Scope 权限体系
| Scope | 权限范围 | 审核 |
|---|---|---|
profile |
查看用户名、头像、ID | 自动通过 |
chat |
Agent 对话、线程管理、容器管理、技能、媒体、定时任务、钱包读取、计费、WebSocket | 需审核 |
credit:read |
查看 Credits 余额和账户状态 | 需审核 |
credit:write |
充值/购买 Credits、兑换 Points(隐含 credit:read) | 需审核 |
注意: 容器删除操作对所有 OAuth token 均被拦截(返回 403)。这是服务端硬限制。
安装
npm / yarn / pnpm
npm install starchild-auth-sdk
# or: yarn add starchild-auth-sdk
# or: pnpm add starchild-auth-sdk
CDN (plain HTML)
<!-- UMD build — use with plain <script> tags -->
<script src="https://unpkg.com/starchild-auth-sdk/dist/starchild-auth.umd.cjs"></script>
<!-- China mirror -->
<script src="https://registry.npmmirror.com/starchild-auth-sdk/latest/files/dist/starchild-auth.umd.cjs"></script>
UMD 构建导出
window.StarchildAuth(构造函数本身,不是 namespace)。 ESM 构建 (starchild-auth.js) 用于<script type="module">或 bundler。
初始化与登录
import { StarchildAuth } from 'starchild-auth-sdk'
const auth = new StarchildAuth({
clientId: 'your-client-id', // 必填
scope: 'profile chat credit:read credit:write', // 空格分隔;需要 Credits 时加上 credit scopes
// clawdApiBase: 'https://preview.iamstarchild.com', // chat/stream HTTP
// clawdWsBase: 'wss://preview.iamstarchild.com', // /ws/sync|terminal|metrics
// creditApiBase: 'https://credit.iamstarchild.com', // 可选,默认生产域名
// 登录成功回调(popup 或 autoLogin 恢复 session 时触发)
onLogin: ({ accessToken, refreshToken, expiresIn, userInfo }) => {
console.log('Logged in:', userInfo.agentName, 'guest=', userInfo.isGuest)
// userInfo = { userInfoId, agentName, agentAvatar, isGuest }
},
onLogout: () => { /* 清除本地状态 */ },
onTokenRefresh: (newToken) => { /* 更新本地 token */ },
onTokenRefreshFailed: () => { /* session 过期 */ },
// 可选配置
autoLogin: true, // 默认 true — 从 localStorage 恢复 session
origin: 'https://iamstarchild.com', // Starchild 站点
refreshInterval: 720000, // 自动刷新间隔 (ms),默认 12 分钟
})
Token 生命周期
- Access Token: 15 分钟有效,自动每 12 分钟刷新;
auth.getToken() - Refresh Token: 7 天有效,存储在
localStorage的starchild_rt_{clientId}key 中;auth.getRefreshToken()仅暴露内存中的同一值 - autoLogin: 页面加载时自动用 refresh token 恢复 session
- visibilitychange: 从后台切回时自动刷新 token
getRefreshToken() 安全模型
- Refresh token 本来就写在集成方 origin 的
localStorage(autoLogin 需要);公开 getter 不扩大威胁面,只是可读内存副本。 - 优先让 SDK 自己刷新:
refreshToken()/ 定时 auto-refresh / visibility 刷新。 - 若你拷贝到自有存储:当作密码——禁止日志、禁止发给第三方后端、禁止放进 URL。
- 集成方 origin 上的 XSS 本来就能读
localStorage;用 CSP、避免 inline script 缓解。
Guest 账号与绑定正式登录方式
没有
loginAsGuest()。Guest 与正式账号走同一条auth.login()主站 popup 流程;用户在主站选择 continue-as-guest(或等价入口)时才会拿到isGuest: true。第三方不要自建 guest 登录。
OAuth 登录可能返回 Guest(临时)账号(`userInfo.i
Установить starchild-auth в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл starchild-auth?
Starchild Auth SDK: add OAuth login to any web app with one SDK. Use when integrating Starchild login into a project (e.g. add Starchild sign-in to my React app, set up OAuth with iamstarchild.com, implement login/logout with Starchild Auth SDK). Also use for local OAuth/CORS testing guidance (localhost:6066 web, third-party localhost origins, browser vs Node).
Как установить скилл starchild-auth?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл starchild-auth запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic