工作階段管理
POST /api/auth/logout
使目前的工作階段 token 失效。
curl -X POST https://auth.panguard.ai/api/auth/logout \
-H "Authorization: Bearer YOUR_TOKEN"
{
"ok": true,
"data": {
"message": "Logged out successfully"
}
}
GET /api/auth/me
回傳已認證使用者的個人資料、訂閱層級和帳號詳細資訊。
curl -X GET https://auth.panguard.ai/api/auth/me \
-H "Authorization: Bearer YOUR_TOKEN"
{
"ok": true,
"data": {
"id": "usr_a1b2c3d4e5f6",
"email": "user@example.com",
"name": "Alice Chen",
"tier": "pro",
"totpEnabled": true,
"machineLimit": 10,
"trialEndsAt": null,
"createdAt": "2026-01-15T08:30:00.000Z",
"updatedAt": "2026-03-01T14:22:00.000Z"
}
}
密碼重設
POST /api/auth/forgot-password
向指定地址發送密碼重設 email。無論該 email 是否存在都回傳 200(防止列舉攻擊)。
curl -X POST https://auth.panguard.ai/api/auth/forgot-password \
-H "Content-Type: application/json" \
-d '{ "email": "user@example.com" }'
{
"ok": true,
"data": {
"message": "If an account with that email exists, a reset link has been sent."
}
}
POST /api/auth/reset-password
使用來自重設 email 的 token 重設密碼。
curl -X POST https://auth.panguard.ai/api/auth/reset-password \
-H "Content-Type: application/json" \
-d '{
"token": "rst_x9y8z7w6v5u4",
"newPassword": "newSecureP@ss"
}'
{
"ok": true,
"data": {
"message": "Password reset successfully"
}
}
{
"ok": false,
"error": "Reset token is invalid or has expired"
}
密碼重設 token 在 1 小時後到期。重設密碼時,所有現有工作階段都會被使其失效。
TOTP 雙因素驗證
POST /api/auth/totp/setup
產生 TOTP 密鑰和 QR code URI,用於設定驗證器 app。
curl -X POST https://auth.panguard.ai/api/auth/totp/setup \
-H "Authorization: Bearer YOUR_TOKEN"
{
"ok": true,
"data": {
"secret": "JBSWY3DPEHPK3PXP",
"otpauthUrl": "otpauth://totp/Panguard:user@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Panguard",
"backupCodes": [
"a1b2c3d4e5",
"f6g7h8i9j0",
"k1l2m3n4o5",
"p6q7r8s9t0",
"u1v2w3x4y5"
]
}
}
請將 backupCodes 儲存在安全的位置。它們是一次性使用的,在此初始回應後無法再次取得。每個備用代碼可在登入時替代 TOTP 代碼使用一次。
POST /api/auth/totp/verify
驗證 TOTP 代碼以完成 2FA 設定。必須在 /totp/setup 之後呼叫以啟用 2FA。
curl -X POST https://auth.panguard.ai/api/auth/totp/verify \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "totpCode": "482917" }'
{
"ok": true,
"data": {
"message": "Two-factor authentication enabled successfully"
}
}
{
"ok": false,
"error": "Invalid TOTP code. Please try again."
}
POST /api/auth/totp/disable
停用 TOTP 雙因素驗證。基於安全考量,需要目前密碼。
curl -X POST https://auth.panguard.ai/api/auth/totp/disable \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "password": "secureP@ssw0rd" }'
{
"ok": true,
"data": {
"message": "Two-factor authentication disabled"
}
}
停用 2FA 會使所有現有備用代碼失效。如果您之後重新啟用 2FA,將會產生一組新的備用代碼。