---
title: OAuth API 參考
description: Platform API v1 的 OAuth：每個操作的路徑、參數、請求與回應欄位、scope、冪等與錯誤，直接取自 API 合約。
url: https://agentlab.cresclab.com/docs/zh-tw/api/oauth
language: zh-Hant
updated: 2026-12-05
---

# OAuth API 參考

Platform API v1 的 OAuth：每個操作的路徑、參數、請求與回應欄位、scope、冪等與錯誤，直接取自 API 合約。

> [!NOTE]
> 由 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](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | The request is invalid. |
| `500` | `application/json`: [LegacyErrorString](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#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=install` at `/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 by `installation_id` or `workspace_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](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#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](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#TokenResponse) 或 [InstallationTokenResponse](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#InstallationTokenResponse) 或 [InstallResult](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#InstallResult) | The tokens, or where an application was installed. Never cached. |
| `400` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | `invalid_grant`, `invalid_request` or `unsupported_grant_type`. |
| `401` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | `invalid_client`: the client authentication is missing, wrong or malformed. |
| `429` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | Too many requests carrying a secret from this address, or tokens for this client. |
| `503` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#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](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#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](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Introspection) | The token's state. Never cached. |
| `400` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | `token` is missing. |
| `401` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | The client credential is missing or wrong. |
| `429` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | Too many requests from this address or client. |
| `503` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#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](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#UserInfo) | The claims the token's scope allows, and the workspace it is bound to. |
| `401` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | No token, or one this endpoint does not honor. |
| `403` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | Sent from a page that is not the application's registered origin. |
| `503` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | Try again. |

## The signed-in person (OpenID Connect userinfo, POST form)

`POST /v1/oauth/userinfo`

| Scope | 身分 | 驗證方式 | Idempotency-Key |
| --- | --- | --- | --- |
| 無 | — | `personToken` | — |

### 回應

| 狀態碼 | 內容 | 說明 |
| --- | --- | --- |
| `200` | `application/json`: [UserInfo](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#UserInfo) | The claims the token's scope allows, and the workspace it is bound to. |
| `401` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | No token, or one this endpoint does not honor. |
| `403` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | Sent from a page that is not the application's registered origin. |
| `503` | `application/json`: [OAuthError](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#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](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#OAuthError) | ID tokens are not configured on this server. |

#### `200` `application/json`

| 欄位 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `keys` | `object`[] | 是 | — |
