身份验证和令牌引导程序
目的:在调用收件箱管理器 API 之前获取不记名令牌并验证身份验证端点行为。
边界注释:
- 此流程调用
auth.inbox-manager.com端点。 - 这些路线不是
api.inbox-manager.comOpenAPI 的一部分。
用户界面流程
- 用户打开注册表单或登录表单。
- UI 将凭据提交至
https://auth.inbox-manager.com/auth/sign-up或/auth/sign-in。 - UI 存储返回的访问令牌和帐户上下文。
- UI 在需要时通过
POST /api/accounts/:account_id/token请求帐户范围的令牌。 - UI 使用返回的令牌作为
Authorization: Bearer <token>代表api.inbox-manager.com。
客户端库流程
const auth = new AuthClient({ baseUrl: "https://auth.inbox-manager.com" });
const session = await auth.signIn({
email,
password,
clientId: "cid_inbox_manager",
});
const accountToken = await auth.issueAccountToken({
accountId: session.profile.active_membership.account_id,
bearerToken: session.tokens.access_token,
audience: "https://api.inbox-manager.com",
});
const api = new InboxManagerClient({
baseUrl: "https://api.inbox-manager.com",
bearerToken: accountToken.access_token,
});
HTTP/curl 流程
AUTH_BASE_URL="https://auth.inbox-manager.com"
ORIGIN="https://app.inbox-manager.com"
CLIENT_ID="cid_inbox_manager"
curl -sS "${AUTH_BASE_URL}/.well-known/jwks.json"
curl -sS -X POST "${AUTH_BASE_URL}/auth/sign-in" \
-H "origin: ${ORIGIN}" \
-H "content-type: application/json" \
--data "{\"client_id\":\"${CLIENT_ID}\",\"email\":\"${EMAIL}\",\"password\":\"${PASSWORD}\",\"csrf_token\":\"${CSRF_TOKEN}\"}"
curl -sS -X POST "${AUTH_BASE_URL}/api/accounts/${ACCOUNT_ID}/token" \
-H "authorization: Bearer ${ACCESS_TOKEN}" \
-H "content-type: application/json" \
--data '{"audience":"https://api.inbox-manager.com"}'
验证脚本
scripts/auth_probe.sh-scripts/auth_bootstrap_accounts.sh