12 cards
Client
The application requesting tokens; the MemberPortal BFF is a confidential client because it can keep `IDP_CLIENT_SECRET` on the server.
Confidential vs public client
A confidential client can keep a secret (BFF, server); a public one cannot (SPA, mobile) so it must use PKCE instead of a secret.
Authorization Code flow
/authorize → user logs in → IdP returns a `code` to the redirect_uri → the client POSTs to `/oauth/token` to exchange the code for id_token/access_token.
/authorize parameters
`response_type=code`, `client_id`, `redirect_uri`, `scope=openid ...`, `state`, `nonce`, `code_challenge`, `code_challenge_method=S256`, optionally `prompt`, `connection`.
`/auth/web/login`
Generates state/nonce/code_verifier, creates SessionID1, stores successUrl/idProvider/channel=Web, 302 to /authorize.
`/auth/web/login-callback`
Check state → error → code → exchange token → verify id_token → get accountNo → Account Attribute API → Login Status API → create SessionID2 → set cookies → delete SessionID1 → 302 successUrl.
client_credentials grant
An M2M grant with no user; the client sends `client_id` + `client_secret` to get an access_token for itself.
`portal-management` client
Used by the BFF to call the Auth0 Management API (`/api/v2/users/*`) at boot and at runtime.
Getting the token at startup
During the boot process the BFF calls `/oauth/token` with grant client_credentials and caches the token in memory along with `expires_at`.
When to refresh the Management token
When less than 5 minutes remain, get a new token before calling the API.
Why the boot-time token is enough for the Management API users endpoints
The Management API authorizes by the client's permissions (e.g. `read:users`) and does not need a user token; the BFF acts on behalf of the user based on the sub in the session.
Management API vs Authentication API
The Management API is for administration (users, connections, metadata) and uses a client_credentials token; the Authentication API is /authorize, /oauth/token, /userinfo, /mfa/* used in user flows.