何时使用 OAuth
注册客户端
根据 RFC 7591,Twenty 支持动态客户端注册。 无需手动设置——以编程方式注册:范围
以空格分隔的字符串请求范围:
scope=api profile
授权码流程
当你的应用代表某个 Twenty 用户执行操作时,请使用此流程。1. 重定向用户以进行授权
用户将看到授权同意界面,并同意或拒绝访问。
2. 处理回调
授权后,Twenty 会重定向回你的redirect_uri:
state 与你发送的值一致。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
采用 PKCE 的授权码流程和用于服务器到服务器访问的客户端凭证。
POST /oauth/register
Content-Type: application/json
{
"client_name": "My Integration",
"redirect_uris": ["https://myapp.com/callback"],
"grant_types": ["authorization_code"],
"token_endpoint_auth_method": "client_secret_post"
}
{
"client_id": "abc123",
"client_secret": "secret456",
"client_name": "My Integration",
"redirect_uris": ["https://myapp.com/callback"]
}
client_secret——之后无法再检索。| 范围 | 访问 |
|---|---|
api | 对 Core 和 Metadata API 的完全读/写访问 |
个人资料 | 读取已认证用户的个人资料信息 |
scope=api profile
GET /oauth/authorize?
client_id=YOUR_CLIENT_ID&
response_type=code&
redirect_uri=https://myapp.com/callback&
scope=api&
state=random_state_value&
code_challenge=CHALLENGE&
code_challenge_method=S256
| 参数 | 必填 | 描述 |
|---|---|---|
client_id | 是 | 你已注册的客户端 ID |
response_type | 是 | 必须为 code |
redirect_uri | 是 | 必须与已注册的重定向 URI 匹配 |
scope | 否 | 以空格分隔的范围(默认为 api) |
状态 | 推荐 | 用于防止 CSRF 攻击的随机字符串 |
code_challenge | 推荐 | PKCE 质询(验证器的 SHA-256 哈希,base64url 编码) |
code_challenge_method | 推荐 | 使用 PKCE 时必须为 S256 |
redirect_uri:
https://myapp.com/callback?code=AUTH_CODE&state=random_state_value
state 与你发送的值一致。
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&
code=AUTH_CODE&
redirect_uri=https://myapp.com/callback&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET&
code_verifier=YOUR_PKCE_VERIFIER
{
"access_token": "eyJhbG...",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "dGhpcyBpcyBh..."
}
GET /rest/companies
Authorization: Bearer ACCESS_TOKEN
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&
refresh_token=YOUR_REFRESH_TOKEN&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET&
scope=api
GET /.well-known/oauth-authorization-server
| 端点 | 目的 |
|---|---|
/.well-known/oauth-authorization-server | 服务器元数据发现 |
/oauth/register | 动态客户端注册 |
/oauth/authorize | 用户授权 |
/oauth/token | 令牌交换与刷新 |
| 环境 | 基础 URL |
|---|---|
| 云端 | https://api.twenty.com |
| 自托管 | https://{your-domain} |
| API 密钥 | OAuth | |
|---|---|---|
| 设置 | 在设置中生成 | 注册客户端并实现流程 |
| 用户上下文 | 无(工作区级) | 特定用户的权限 |
| 最适合 | 脚本、内部工具 | 外部应用、多用户集成 |
| 令牌轮换 | 手动 | 通过刷新令牌自动完成 |
| 范围限定的访问 | 完整的 API 访问 | 通过范围实现细粒度控制 |
此页面对您有帮助吗?