IM
ZH-TW
文件首頁
選單
指南

身份驗證後端管理流程

使用私有後端用戶端對「auth.inbox-manager.com」進行身份驗證並執行特權使用者/帳戶/會員操作。

inbox-manager client-flow

身份驗證後端管理流程

目的:使用私有後端用戶端對auth.inbox-manager.com進行身份驗證並執行特權使用者/帳戶/成員資格操作。

邊界註:

  • 本指南針對 auth.inbox-manager.comapi.inbox-manager.com
  • 這些端點位於api.inbox-manager.com OpenAPI 之外。

觀眾規則

  • 此客戶端用於呼叫api.inbox-manager.com / auth.inbox-manager.com API。
  • 令牌受眾應為https://api.inbox-manager.com
  • 公共應用程式用戶端與受眾https://api.inbox-manager.com保持分離。

使用者介面流程

  1. 不使用瀏覽器。
  2. 後端服務透過客戶端憑證鑄造 M2M 令牌。
  3. 後端執行使用者/帳號/會員管理API。
  4. 後端在內部作業/日誌系統中記錄結果。

客戶端庫流程

const auth = new OAuthClient({
  tokenUrl: "https://auth.inbox-manager.com/oauth2/token",
  clientId: process.env.AUTH_BACKEND_ADMIN_CLIENT_ID!,
  clientSecret: process.env.AUTH_BACKEND_ADMIN_CLIENT_SECRET!,
});

const token = await auth.clientCredentials({
  audience: "https://api.inbox-manager.com",
});

const authApi = new InboxManagerAdminClient({
  baseUrl: "https://api.inbox-manager.com",
  bearerToken: token.access_token,
});

const user = await authApi.createApplicationUser(appId, { status: "active" });
const account = await authApi.createChildAccount(parentAccountId, {
  name: "ops-provisioned",
});
const membership = await authApi.addAccountMember(
  account.id,
  user.id,
  "viewer",
);

HTTP/curl 流程

curl -sS -X POST "https://auth.inbox-manager.com/oauth2/token" \
  -H "content-type: application/json" \
  --data "{
    \"grant_type\": \"client_credentials\",
    \"client_id\": \"${AUTH_BACKEND_ADMIN_CLIENT_ID}\",
    \"client_secret\": \"${AUTH_BACKEND_ADMIN_CLIENT_SECRET}\",
    \"audience\": \"https://api.inbox-manager.com\"
  }"

然後調用:

-POST /api/applications/:application_id/users -POST /api/accounts/:account_id/accounts

  • POST /api/accounts/:account_id/members -PATCH /api/accounts/:account_id/members/:member_id
  • DELETE /api/accounts/:account_id/members/:member_id -PATCH /api/accounts/:account_id -DELETE /api/accounts/:account_id
  • DELETE /api/users/:user_id

驗證腳本

-scripts/auth_backend_admin_flow.sh