取得 API Key 與驗證方式

開發者 API 用 API Key 驗證(Authorization: Bearer <API Key>);後台與錢包 API 用 JWT access token + refresh token。

檢視 Markdown

建立一把 API Key

  1. 1登入商家後台,前往「開發者」→「API 金鑰」。
  2. 2點「建立金鑰」,勾選這把金鑰需要的權限範圍(scope)。
  3. 3金鑰的完整內容(rbp_test_...)只會顯示這一次,請立即複製並存到安全的地方(例如 secret manager)。之後只能看到前綴。
金鑰只能放在你後端的環境變數,絕對不能寫進前端程式碼或送到瀏覽器。如果金鑰外洩,立即到後台撤銷(撤銷後立刻失效)。

在請求中帶上金鑰

curl -sS "$BASE/api/Product" \
  -H "Authorization: Bearer $API_KEY"

登入型 API:JWT + Refresh Token

ReBate Pay 自己的平台後台(Admin*)、商家後台(Merchant*)與消費者錢包(Member*)API 不用 API Key,而是先登入取得 token。你的 App 或整合要代表某個登入者操作時也用這套方式。

對象登入換發登出
平台管理員POST /api/AdminAuth/Login { name, password }POST /api/AdminAuth/RefreshPOST /api/AdminAuth/Logout
企業/商家、個人商家POST /api/MerchantAuth/Login { email, password, accountType }POST /api/MerchantAuth/RefreshPOST /api/MerchantAuth/Logout
消費者錢包POST /api/MemberAuth/Login { email } 寄送登入連結 → POST /api/MemberAuth/Verify { loginToken }POST /api/MemberAuth/RefreshPOST /api/MemberAuth/Logout
curl -sS -X POST "$BASE/api/MerchantAuth/Login" -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","password":"…","accountType":"Business"}'
  • accessToken 是 JWT,15 分鐘(expiresIn 秒)後失效;每次請求放在 Authorization: Bearer。
  • 過期時 API 回 401 TOKEN_EXPIRED,請用 refreshToken 呼叫對應的 */Refresh 換發新的一組 token。refreshToken 每次換發都會輪替,舊的立即失效;同一個 refreshToken 用兩次會收到 401 INVALID_REFRESH_TOKEN,請重新登入。
  • 登出會撤銷 refreshToken,之後用舊 token 呼叫一律 401。
  • GET /api/Auth/Identity 回傳目前 token 的登入者(userType 為 Admin、Merchant、Member)。
  • 用錯類型的 token(例如用商家 token 呼叫 Admin*)會收到 403 WRONG_TOKEN_TYPE;API Key 不能呼叫登入型 API,JWT 也不能呼叫開發者 API。
  • refreshToken 等同密碼,只能存在安全的地方(例如 App 的安全儲存區),不要放進網址或 log。

常見的權限範圍(scope)

每把金鑰只擁有你勾選的 scope;「寫入」自動包含「讀取」。建議只勾選你真的需要的範圍。完整清單見 API 金鑰與安全。

Scope用途
products:read / products:write商品目錄
customers:read / customers:write顧客資料
subscriptions:read / subscriptions:write訂閱
payments:write建立/嘗試付款(高風險:會實際請款)
refunds:write退款(高風險:會實際退款)
webhooks:write註冊 Webhook endpoint