OAuth login flow
The social login flow involves three steps:- Redirect — Your app redirects the user to the provider’s login page
- Callback — The provider redirects back to your app with a
challenge_token - Finalize — Your app sends the
challenge_tokento complete authentication
verify_email enabled and the IdP returns an email it has not verified, an extra OTP step happens between Callback and Finalize — see Verify email via OTP below.
How is the OAuth flow secured?
How is the OAuth flow secured?
The entire flow is protected by PKCE (Proof Key for Code Exchange). The SDK generates a unique
code_verifier and code_challenge pair for each login attempt, and the challenge_token can only be finalized once. This protects against:- Authorization code interception — A stolen
challenge_tokenis useless without thecode_verifier, which never leaves the browser - Replay attacks — The
challenge_tokenis invalidated after a single use - Cross-site request forgery (CSRF) — The server validates that the finalize request matches the original authorization request
Redirect to the provider
UseloginWithOAuth to redirect the user to the provider’s authorization page:
redirectURI must match the redirect URI configured in your OAuth provider settings.
Handle the callback
When the provider redirects back to your app, extract thechallenge_token from the URL and finalize the login:
Verify email via OTP
When the OAuth provider config hasverify_email enabled and the IdP returns an unverified email, Auth does not finalize the login on the callback. Instead, the redirect carries status=otp_required alongside the challenge_token, and finalizeOAuthLogin returns:
email. Your app shows an OTP screen, the user enters the code, and you call checkOTP:
checkOTP resolves successfully the user is fully logged in — call client.refresh() (or whatever your app uses to load the session) and proceed.
Try it
Try it
Replace
src/App.jsx with:src/App.jsx