Auth 啟動與權杖
目的:在呼叫需要驗證的 jsonlog 路由前,取得帳戶範圍 Bearer 權杖。
邊界說明:
- 此流程會呼叫
auth.jsonlog.com端點。 - 這些路由不屬於 jsonlog OpenAPI。
前置條件
- JsonLog 服務可連線(本機預設
http://localhost:3002)。 - auth 環境已為你的來源與 client 正確設定。
- 若使用啟動腳本,需可使用
node、curl、jq。
UI 流程
- 使用者透過為 jsonlog 設定的 auth client 登入。
- client 取得包含帳戶聲明(
acc)的 access token。 - client 對受保護的 jsonlog 路由送出
Authorization: Bearer <token>。
API/Script 流程
使用啟動 helper 建立測試身份並輸出帳戶權杖清單。
cd jsonlog
set -a && source .env && set +a
TEST_EMAIL_DOMAIN="example.com" npm run auth:bootstrap
從輸出的清單中擷取 account_access_token 以呼叫 /query。
HTTP/curl 流程
AUTH_BASE_URL="https://auth.jsonlog.com"
JSONLOG_BASE_URL="http://localhost:3002"
ACCESS_TOKEN="<account_scoped_token>"
curl -sS "${AUTH_BASE_URL}/.well-known/jwks.json?client_id=cid_jsonlog"
curl -sS -X POST "${JSONLOG_BASE_URL}/query" \
-H "authorization: Bearer ${ACCESS_TOKEN}" \
-H "content-type: application/json" \
--data '{"start_ts": 1700000000000, "end_ts": 1700000600000}'
驗證
/query缺少或無效權杖時回傳401。- 有效且包含帳戶聲明的權杖會回傳
200與查詢回應封裝。