stackone-connect
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStackOne Connect — Account Linking
StackOne Connect — 账户关联
Important
重要说明
Before writing code, fetch the latest documentation:
- Fetch for the current connection flow
https://docs.stackone.com/guides/connect-tools-overview - Fetch for the latest Hub component API
https://www.npmjs.com/package/@stackone/hub
The Hub component is in active beta — props and peer dependencies change between versions.
编写代码前,请获取最新文档:
- 访问获取当前连接流程
https://docs.stackone.com/guides/connect-tools-overview - 访问获取最新Hub组件API
https://www.npmjs.com/package/@stackone/hub
Hub组件目前处于活跃测试版——不同版本间的props和peer dependencies会有所变化。
Instructions
操作步骤
Step 1: Choose a connection method
步骤1:选择连接方式
| Method | When to use |
|---|---|
| Embedded Hub | In-app integration picker — users stay in your app |
| Auth Link | Email onboarding or external flows — standalone URL, valid 5 days |
| Dashboard | Internal testing only — never for production |
If unsure, recommend the Embedded Hub. It provides the best user experience.
| 方式 | 使用场景 |
|---|---|
| 嵌入式Hub(Embedded Hub) | 应用内集成选择器——用户无需离开你的应用 |
| 授权链接(Auth Link) | 邮件引导或外部流程——独立URL,有效期5天 |
| 控制台(Dashboard) | 仅用于内部测试——切勿用于生产环境 |
若不确定,推荐使用嵌入式Hub,它能提供最佳用户体验。
Step 2: Create a Connect Session (backend)
步骤2:创建连接会话(后端)
Your backend creates a session token that the frontend uses to initialize the Hub:
bash
curl -X POST https://api.stackone.com/connect_sessions \
-H "Authorization: Basic $(echo -n 'YOUR_API_KEY:' | base64)" \
-H "Content-Type: application/json" \
-d '{
"origin_owner_id": "customer-123",
"origin_owner_name": "Acme Inc"
}'The response includes a field. Pass this to the frontend.
tokenTo filter which providers appear in the Hub:
json
{
"origin_owner_id": "customer-123",
"origin_owner_name": "Acme Inc",
"provider": "bamboohr",
"categories": ["hris"]
}Fetch for the full request/response schema.
https://docs.stackone.com/platform/api-reference/connect-sessions/create-connect-session你的后端需创建一个会话令牌,供前端用于初始化Hub:
bash
curl -X POST https://api.stackone.com/connect_sessions \
-H "Authorization: Basic $(echo -n 'YOUR_API_KEY:' | base64)" \
-H "Content-Type: application/json" \
-d '{
"origin_owner_id": "customer-123",
"origin_owner_name": "Acme Inc"
}'响应结果包含字段,请将其传递给前端。
token如需筛选Hub中显示的服务商:
json
{
"origin_owner_id": "customer-123",
"origin_owner_name": "Acme Inc",
"provider": "bamboohr",
"categories": ["hris"]
}访问获取完整的请求/响应schema。
https://docs.stackone.com/platform/api-reference/connect-sessions/create-connect-sessionStep 3: Initialize the Hub (frontend)
步骤3:初始化Hub(前端)
bash
npm install @stackone/hubtsx
import { StackOneHub } from "@stackone/hub";
function ConnectorPage() {
const [token, setToken] = useState<string>();
useEffect(() => {
fetchConnectSessionToken().then(setToken);
}, []);
if (!token) return <div>Loading...</div>;
return (
<StackOneHub
token={token}
onSuccess={(account) => {
// Store account.id — you'll need it for all subsequent API calls
console.log("Connected:", account.id, account.provider);
}}
onCancel={() => console.log("User cancelled")}
onClose={() => console.log("Hub closed")}
/>
);
}For the full props API and theming options, consult .
references/hub-reference.mdbash
npm install @stackone/hubtsx
import { StackOneHub } from "@stackone/hub";
function ConnectorPage() {
const [token, setToken] = useState<string>();
useEffect(() => {
fetchConnectSessionToken().then(setToken);
}, []);
if (!token) return <div>Loading...</div>;
return (
<StackOneHub
token={token}
onSuccess={(account) => {
// 存储account.id——后续所有API调用都需要它
console.log("Connected:", account.id, account.provider);
}}
onCancel={() => console.log("User cancelled")}
onClose={() => console.log("Hub closed")}
/>
);
}如需完整的props API和主题定制选项,请查阅。
references/hub-reference.mdStep 4: Set up webhook listeners
步骤4:设置Webhook监听器
Webhooks are required for Auth Links (no frontend callbacks) and recommended for the Embedded Hub:
| Event | When it fires |
|---|---|
| New account linked |
| Credentials refreshed |
| Account disconnected |
Fetch for the webhook payload format and setup instructions.
https://docs.stackone.com/guides/webhooksWebhook是授权链接(无前端回调)的必需配置,同时也是嵌入式Hub的推荐配置:
| 事件 | 触发时机 |
|---|---|
| 新账户关联成功时 |
| 凭证刷新时 |
| 账户断开关联时 |
访问获取Webhook负载格式及设置说明。
https://docs.stackone.com/guides/webhooksStep 5: Verify the connection
步骤5:验证连接
After receiving or the webhook, make a test API call:
onSuccessaccount.createdbash
curl https://api.stackone.com/accounts/{account_id} \
-H "Authorization: Basic $(echo -n 'YOUR_API_KEY:' | base64)"A response with confirms the connection is working.
200status: "active"收到回调或 Webhook后,发起测试API调用:
onSuccessaccount.createdbash
curl https://api.stackone.com/accounts/{account_id} \
-H "Authorization: Basic $(echo -n 'YOUR_API_KEY:' | base64)"返回状态码且,则表明连接正常工作。
200status: "active"Examples
示例
Example 1: User wants to add an integration picker to a React app
示例1:用户希望在React应用中添加集成选择器
User says: "I want to let my customers connect their BambooHR account"
Actions:
- Create a backend endpoint that calls with
POST /connect_sessionsprovider: "bamboohr" - Return the session token to the frontend
- Install and render
@stackone/hub<StackOneHub token={token} /> - Handle to store the account ID
onSuccess - Set up a webhook endpoint for as a backup
account.created
Result: Working integration picker that filters to BambooHR only.
用户需求:“我想让我的客户连接他们的BambooHR账户”
操作步骤:
- 创建后端端点,调用并传入
POST /connect_sessionsprovider: "bamboohr" - 将会话令牌返回给前端
- 安装并渲染
@stackone/hub<StackOneHub token={token} /> - 处理回调以存储账户ID
onSuccess - 设置Webhook端点作为备份
account.created
结果:可正常工作的集成选择器,仅显示BambooHR选项。
Example 2: User wants to send connection links via email
示例2:用户希望通过邮件发送连接链接
User says: "I need to onboard customers by email, not in-app"
Actions:
- Create a Connect Session with set to the customer
origin_owner_id - Generate an auth link from the session (fetch auth link docs)
- Set up webhook listeners — auth links have no frontend callbacks
- Send the link via email (valid for 5 days)
Result: Customer clicks link, authenticates, webhook fires with account details.
用户需求:“我需要通过邮件引导客户,而非在应用内完成”
操作步骤:
- 创建连接会话,将设置为对应客户
origin_owner_id - 从会话生成授权链接(请查阅授权链接文档)
- 设置Webhook监听器——授权链接无前端回调
- 通过邮件发送链接(有效期5天)
结果:客户点击链接完成认证后,Webhook会触发并返回账户详情。
Troubleshooting
故障排查
Hub component doesn't render
Hub组件无法渲染
Cause: Missing peer dependencies.
- requires:
@stackone/hub,react,react-dom,react-hook-form,@hookform/resolverszod - Check that versions match — fetch the NPM page for exact version constraints
- Verify the session token is valid and not expired
原因:缺少peer dependencies。
- 依赖:
@stackone/hub、react、react-dom、react-hook-form、@hookform/resolverszod - 检查版本是否匹配——请访问NPM页面获取确切版本约束
- 验证会话令牌是否有效且未过期
Connect Session token expired
连接会话令牌过期
Cause: Tokens are short-lived.
- Generate a new token for each Hub initialization
- Do not cache tokens across sessions
原因:令牌有效期较短。
- 每次初始化Hub时生成新令牌
- 请勿跨会话缓存令牌
onSuccess fires but account status is "error"
onSuccess触发但账户状态为“error”
Cause: Provider-side authentication succeeded but StackOne couldn't sync data.
- Check the account details in the dashboard for the specific error
- Common cause: insufficient permissions on the provider side
- The provider may require additional OAuth scopes
原因:服务商端认证成功,但StackOne无法同步数据。
- 在控制台中查看账户详情以获取具体错误信息
- 常见原因:服务商端权限不足
- 服务商可能需要额外的OAuth权限范围
Webhooks not arriving
Webhook未送达
Cause: Webhook endpoint configuration issue.
- Verify the endpoint URL is publicly accessible (not localhost)
- Check the webhook signing secret matches
- Fetch for the verification process
https://docs.stackone.com/guides/webhooks
原因:Webhook端点配置问题。
- 验证端点URL是否可公开访问(不能是localhost)
- 检查Webhook签名密钥是否匹配
- 访问获取验证流程
https://docs.stackone.com/guides/webhooks