Backend 整合
AM 透過 JWKS 提供公開金鑰、透過 OIDC Discovery 提供設定資訊,這些都是任何 JWT 函式庫都能使用的標準協定。
你可以在本地驗證 token、信任 claims,並據此授權請求。
Token 驗證流程
端點
| Endpoint | 用途 |
|---|---|
/.well-known/jwks.json | 公開簽章金鑰 |
/.well-known/openid-configuration | OIDC Discovery 文件 |
/oauth2/introspect | Refresh token introspection |
JWKS
取得用於本地驗證的公開金鑰:
GET /.well-known/jwks.json
{
"keys": [
{
"kty": "RSA",
"use": "sig",
"kid": "key_...",
"alg": "RS256",
"n": "0vx7agoebG...",
"e": "AQAB"
}
]
}
在金鑰輪替期間可能同時存在多把金鑰。請用 JWT header 的 kid claim 進行對應。
OIDC Discovery
可透過 Discovery 文件自動設定 client:
GET /.well-known/openid-configuration
回傳內容包含端點、支援演算法與能力,符合 OpenID Connect Discovery 規範。
JWT Claims
已驗證 token 會包含:
| Claim | 說明 |
|---|---|
iss | Issuer URL |
sub | Subject(user ID 或 client ID) |
aud | 預期受眾 |
exp | 到期時間(Unix timestamp) |
iat | 簽發時間(Unix timestamp) |
scope | 授與權限 |
cid | Client ID |
app | Application ID |
acc | 目前帳戶 ID |
uid | User ID(使用者驗證時) |
role | 在目前帳戶中的角色 |
快取
- 快取 JWKS 回應(使用 ETag/If-None-Match)
- 驗章失敗時立即重新抓取(處理金鑰輪替)
- 建議 TTL:1 小時
Token Introspection
當你需要驗證 refresh token,或需要權威性驗證時:
POST /oauth2/introspect
Content-Type: application/x-www-form-urlencoded
token=...&client_id=...&client_secret=...
會回傳 active: true/false 與 token claims。Access token 為 JWT,能本地驗證時優先透過 JWKS 進行。
相關
- OAuth - Token 簽發
- 用戶端 - 用戶端設定
- Client Key - 簽章金鑰