OAuth token 端點
/oauth/tokenOAuth token 端點:支援 authorization_code 與 refresh_token。
此端點不需要 API Key。
請求
Base URL:https://api.bluehola.com
請求本文
請求本文為必填。
請求本文欄位
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
grant_type | string | 是 | authorization_code 或 refresh_token |
client_id | string | 是 | |
client_secret | string | 是 | 用戶端驗證方式就是它——所以本端點不掛 API Key 驗證 |
code | string | 否 | grant_type=authorization_code 時必填 |
redirect_uri | string | 否 | grant_type=authorization_code 時必填,且必須與簽發時逐字一致(RFC 6749 §4.1.3) |
code_verifier | string | 否 | 授權時帶了 code_challenge 就必須帶它,否則 400——允許省略等於讓截獲 code 的人不傳這個值就能繞過整個 PKCE |
refresh_token | string | 否 | grant_type=refresh_token 時必填 |
Content-Type:application/json
Schema:
{
"type": "object",
"properties": {
"grant_type": {
"type": "string",
"description": "string · 必填 — `authorization_code` 或 `refresh_token`"
},
"client_id": {
"type": "string",
"description": "string · 必填 — "
},
"client_secret": {
"type": "string",
"description": "string · 必填 — 用戶端驗證方式就是它——所以本端點**不掛 API Key 驗證**"
},
"code": {
"type": "string",
"description": "string · 可選 — grant_type=authorization_code 時必填"
},
"redirect_uri": {
"type": "string",
"description": "string · 可選 — grant_type=authorization_code 時必填,且必須與簽發時**逐字一致**(RFC 6749 §4.1.3)"
},
"code_verifier": {
"type": "string",
"description": "string · 可選 — 授權時帶了 code_challenge 就**必須**帶它,否則 400——允許省略等於讓截獲 code 的人不傳這個值就能繞過整個 PKCE"
},
"refresh_token": {
"type": "string",
"description": "string · 可選 — grant_type=refresh_token 時必填"
}
},
"required": [
"grant_type",
"client_id",
"client_secret"
]
}
回應
| 狀態碼 | 說明 |
|---|---|
200 | OK |
4xx | 用戶端錯誤 |
200 回應 Schema
{
"$ref": "#/components/schemas/OAuthTokenResponse"
}
通用錯誤信封及處理建議見錯誤代碼。
補充說明
回應
access_token、refresh_token、token_type: Bearer、expires_in(秒)、scope、account_id、project_id、connection_id。
有效期與輪替
access token 1 小時,refresh token 30 天。每次 refresh 都會輪替:舊的一對立即撤銷,簽發全新一對。這不是為了省事——refresh token 洩漏後,輪替讓洩漏者與真正的用戶端只有一個能繼續使用,另一個下次 refresh 失敗即是異常信號;而「延長同一筆效期」會讓洩漏的副本永久可用且沒有任何跡象。
失敗語義
authorization code 的「不存在 / 已用過 / 已過期」回傳同一句文案,刻意不區分——區分開來這個端點就成了 code 狀態的探測器。code 的消費用一條條件 UPDATE 完成(WHERE used_at IS NULL AND expires_at > now(),依資料庫時鐘判定),而不是先查再寫:兩個並行請求會同時通過查詢各換到一份 token,而授權碼重放正是 OAuth 最經典的攻擊。
用 access token 呼叫業務端點
Authorization: Bearer oat_...,與 API Key 使用相同的請求標頭。Access token 的可存取範圍固定為授權時選擇的 Business Portfolio,不能透過請求參數擴大,也不能存取其他客戶資產。