12 thẻ
Client
Ứng dụng xin token; BFF MemberPortal là confidential client vì giữ được `IDP_CLIENT_SECRET` phía server.
Confidential vs public client
Confidential giữ được secret (BFF, server); public không giữ được (SPA, mobile) nên phải dùng PKCE thay secret.
Authorization Code flow
/authorize → user login → IdP trả `code` về redirect_uri → client POST `/oauth/token` đổi code lấy id_token/access_token.
Tham số /authorize
`response_type=code`, `client_id`, `redirect_uri`, `scope=openid ...`, `state`, `nonce`, `code_challenge`, `code_challenge_method=S256`, tuỳ chọn `prompt`, `connection`.
`/auth/web/login`
Sinh state/nonce/code_verifier, tạo SessionID1, lưu successUrl/idProvider/channel=Web, 302 tới /authorize.
`/auth/web/login-callback`
Kiểm tra state → error → code → đổi token → verify id_token → lấy accountNo → Account Attribute API → Login Status API → tạo SessionID2 → set cookie → xoá SessionID1 → 302 successUrl.
client_credentials grant
Grant M2M không có user; client gửi `client_id` + `client_secret` đổi access_token cho chính nó.
Client `portal-management`
BFF dùng để gọi Auth0 Management API (`/api/v2/users/*`) khi boot và trong runtime.
Lấy token lúc khởi động
Trong boot process BFF gọi `/oauth/token` grant client_credentials, cache token trong memory kèm `expires_at`.
Refresh Management token khi nào
Khi thời gian còn lại < 5 phút, lấy token mới trước khi gọi API.
Vì sao token lúc boot đủ để gọi Management API users
Management API phân quyền theo permission của client (vd `read:users`), không cần token của user; BFF thao tác thay user dựa trên sub trong session.
Management API vs Authentication API
Management API quản trị (user, connection, metadata) dùng token client_credentials; Authentication API là /authorize, /oauth/token, /userinfo, /mfa/* dùng trong flow user.