OAuth API 参考
Platform API v1 的 OAuth:每个操作的路径、参数、请求与回应字段、scope、幂等与错误,直接取自 API 合约。
由 API 合约(Agent Lab Platform API 1.0.0-alpha.1)产生。说明文本是合约的英文原文。
Sign-in and tokens for applications (RFC 6749, 7009, 7662; OpenID Connect).
Start authorization (authorization code with PKCE)#
GET /v1/oauth/authorize
A browser navigation, not an API call. scope=install asks a workspace administrator to install the application (never combined with another scope). A valid request is redirected to the consent screen (or, for an operators' own application with a signed-in person, straight back to the client). An invalid one is answered here and never redirected to an unverified URI.
| Scope | 身分 | 验证方式 | Idempotency-Key |
|---|---|---|---|
| 无 | — | 无 | — |
参数
| 名称 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
client_id | query | string | 是 | — |
redirect_uri | query | string | 是 | — |
code_challenge | query | string | 是 | — |
code_challenge_method | query | string | 是 | 可用值: S256. |
response_type | query | string | 否 | — |
state | query | string | 否 | — |
resource | query | string | 否 | — |
scope | query | string | 否 | — |
nonce | query | string | 否 | — |
organization_id | query | string (uuid) | 否 | The workspace to preselect on the consent screen, by id. A hint only. |
organization | query | string | 否 | The same hint by the workspace's short name. |
回应
| 状态码 | 内容 | 说明 |
|---|---|---|
302 | — | To the consent screen, or back to the client. |
400 | application/json: OAuthError | The request is invalid. |
500 | application/json: LegacyErrorString | The consent screen's address is misconfigured. |
Exchange a code, refresh a token, or get an installation token#
POST /v1/oauth/token
Three grants:
authorization_code(with PKCE): a person's sign-in. When the code came from an install request (scope=installat/v1/oauth/authorize), the answer names the installation and carries no token (InstallResult).refresh_token: a new access token for the same sign-in.client_credentials: an installed application's server asks for a one-hour installation token, naming the installation byinstallation_idorworkspace_id. No refresh token: the application asks again. Refused alike unless the client authenticated with its secret, the installation is live for that client, and its workspace still allows it.
A workspace application authenticates with its secret, by HTTP Basic (client_secret_basic, each half form-encoded first) or in the body (client_secret_post); both at once must name the same client and the secret may be sent only once. Any other client is public and sends only client_id. Requests that carry a secret are rate limited per address.
| Scope | 身分 | 验证方式 | Idempotency-Key |
|---|---|---|---|
| 无 | — | clientSecretBasic | — |
请求内容
application/x-www-form-urlencoded: TokenRequest
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
grant_type | string | 是 | 可用值: authorization_code, refresh_token, client_credentials. |
code | string | 否 | — |
code_verifier | string | 否 | — |
client_id | string | 否 | — |
client_secret | string | 否 | client_secret_post; a workspace application's secret. |
redirect_uri | string | 否 | — |
resource | string | 否 | — |
refresh_token | string | 否 | — |
installation_id | string | 否 | client_credentials: the installation, by id. |
workspace_id | string | 否 | client_credentials: the installation, by the workspace it is in. |
scope | string | 否 | client_credentials: install or absent. |
回应
| 状态码 | 内容 | 说明 |
|---|---|---|
200 | application/json: TokenResponse 或 InstallationTokenResponse 或 InstallResult | The tokens, or where an application was installed. Never cached. |
400 | application/json: OAuthError | invalid_grant, invalid_request or unsupported_grant_type. |
401 | application/json: OAuthError | invalid_client: the client authentication is missing, wrong or malformed. |
429 | application/json: OAuthError | Too many requests carrying a secret from this address, or tokens for this client. |
503 | application/json: OAuthError | Try again. |
Revoke a token (RFC 7009)#
POST /v1/oauth/revoke
Answers 200 whether or not the token named anything.
| Scope | 身分 | 验证方式 | Idempotency-Key |
|---|---|---|---|
| 无 | — | 无 | — |
请求内容
application/x-www-form-urlencoded: object
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
token | string | 否 | — |
client_id | string | 否 | — |
回应
| 状态码 | 内容 | 说明 |
|---|---|---|
200 | — | Revoked, or nothing to revoke. |
503 | application/json: OAuthError | Storage is unavailable; try again. |
Introspect a token (RFC 7662)#
POST /v1/oauth/introspect
The application's server asks whether a bearer token is one the platform honors, and as whom: an operators' application about its sign-in tokens, a workspace application about its sign-in and installation tokens. Server to server only (no CORS). A token that is unknown, expired, revoked, for another audience or issued to any other client answers {"active": false}.
| Scope | 身分 | 验证方式 | Idempotency-Key |
|---|---|---|---|
| 无 | — | clientSecretBasic | — |
请求内容
application/x-www-form-urlencoded: object
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
token | string | 是 | — |
token_type_hint | string | 否 | — |
回应
| 状态码 | 内容 | 说明 |
|---|---|---|
200 | application/json: Introspection | The token's state. Never cached. |
400 | application/json: OAuthError | token is missing. |
401 | application/json: OAuthError | The client credential is missing or wrong. |
429 | application/json: OAuthError | Too many requests from this address or client. |
503 | application/json: OAuthError | Try again. |
The signed-in person (OpenID Connect userinfo)#
GET /v1/oauth/userinfo
For a sign-in's token of any client. Only an operators' application's page may call it from a browser; any other client calls it from its server.
| Scope | 身分 | 验证方式 | Idempotency-Key |
|---|---|---|---|
| 无 | — | personToken | — |
回应
| 状态码 | 内容 | 说明 |
|---|---|---|
200 | application/json: UserInfo | The claims the token's scope allows, and the workspace it is bound to. |
401 | application/json: OAuthError | No token, or one this endpoint does not honor. |
403 | application/json: OAuthError | Sent from a page that is not the application's registered origin. |
503 | application/json: OAuthError | Try again. |
The signed-in person (OpenID Connect userinfo, POST form)#
POST /v1/oauth/userinfo
| Scope | 身分 | 验证方式 | Idempotency-Key |
|---|---|---|---|
| 无 | — | personToken | — |
回应
| 状态码 | 内容 | 说明 |
|---|---|---|
200 | application/json: UserInfo | The claims the token's scope allows, and the workspace it is bound to. |
401 | application/json: OAuthError | No token, or one this endpoint does not honor. |
403 | application/json: OAuthError | Sent from a page that is not the application's registered origin. |
503 | application/json: OAuthError | Try again. |
The keys that sign ID tokens#
GET /v1/oauth/jwks.json
| Scope | 身分 | 验证方式 | Idempotency-Key |
|---|---|---|---|
| 无 | — | 无 | — |
回应
| 状态码 | 内容 | 说明 |
|---|---|---|
200 | application/json: object | A JSON Web Key Set (public keys only). |
404 | application/json: OAuthError | ID tokens are not configured on this server. |
200 application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
keys | object[] | 是 | — |