This document details the flow for logging in using a Phone Number and OTP.
1. The Flow Chart
2. Step-by-Step Logic
Step 1: Request OTP
- Endpoint:
POST /auth/login/phone - Body:
phone(E.164 format:+1234567890). - Logic:
- Clean/Validate phone number.
- Find
userwherephone = ?. - If found:
- Generate 6-digit OTP.
- Store in
verifications(identifier=phone,type='login'). - Send SMS (via Twilio/SNS - Provider TBD).
- Return 200 OK.
Step 2: Verify OTP
- Endpoint:
POST /auth/login/phone/verify - Body:
phone,code. - Logic:
- Find valid OTP in
verifications. - If valid:
- Get
userby phone. - Check 2FA: If user also has 2FA enabled (e.g., TOTP), this OTP counts as "Knowledge" + "Possession"? Or just "Possession"?
-
- Policy*: Phone OTP usually counts as strong authentication (Possession of SIM). We can skip further 2FA unless strictly required.
- Issue Access/Refresh Tokens.
- Get
- Find valid OTP in
3. Registration with Phone
If the phone number is new, the flow redirects to Registration:
- Verify Phone (OTP).
POST /registerwithphone+verification_token.