How Firebase OTP works
From the app asking which sign-in methods exist to a verified Firebase phone token and an issued device token — with the SMS fallback explained.
How Firebase OTP works
Signing in to the mobile app with a phone number does not go through the CRM's own SMS stack by default — it goes through Firebase Phone Authentication. Firebase proves the person owns the number; the CRM then verifies that proof server-side and issues the device its own token. Here is the full loop, including the SMS fallback for workspaces that prefer their own provider.
The loop in plain language
- The app asks the CRM which sign-in methods this workspace allows.
- The person chooses phone sign-in and enters their number.
- Firebase sends the OTP by SMS; the person types the code.
- Firebase hands the app a signed proof (an ID token) that the number was verified.
- The app gives that proof to the CRM. The server verifies it against Google's servers — the app cannot fake it.
- The CRM checks the person belongs to an active workspace, then issues a device token and registers the phone.
- Every later API call uses that device token.
sequenceDiagram
autonumber
participant A as Android app
participant C as CRM mobile API
participant F as Firebase Auth
participant G as Google Identity Toolkit
A->>C: GET /api/v1/mobile/auth-config
C-->>A: Enabled sign-in methods
A->>F: Phone sign-in (runtime Firebase init)
F->>A: SMS OTP
A->>F: OTP entered
F-->>A: Firebase ID token (proof)
A->>C: POST /api/v1/mobile/otp/verify (token)
C->>G: getAccountInfo — verify the token server-side
G-->>C: Verified phone number
C->>C: Resolve workspace, check subscription active
C-->>A: Device token (64 chars, 90-day TTL)
The technical trace
- Auth config.
GET /api/v1/mobile/auth-configresolves capabilities throughMobileAuthConfigResolver: platform defaults from theMobileAuthSettingspanel (settings groupmobile_auth), overridden per tenant bytenants.settings.mobile_auth. Flags:email_password_enabled,phone_password_enabled,email_otp_enabled,phone_otp_enabled. The app renders only the methods enabled for this workspace. - OTP start.
POST /api/v1/mobile/otp/startwith the identifier:- Email OTP — the server generates the code and mails it through the tenant's SMTP configuration.
- Phone OTP — either Firebase sends the SMS client-side (Firebase phone sign-in), or the workspace's SMS provider (tenant messaging settings) delivers a server-side code. If neither is configured, the API answers
otp_unavailable: "Phone OTP is not configured for this workspace."
- Limits. Starts are capped at 3 per identifier and 10 per IP per 10 minutes; verification allows 5 attempts. Rate-limit responses are deliberate safety, not errors.
- Verification.
POST /api/v1/mobile/otp/verify. For Firebase, the server validates the app-provided ID token against Google's Identity ToolkitgetAccountInfoendpoint — no Admin SDK, nogoogle-services.json(the Android app initialises Firebase at runtime from fetched config). For SMS/email codes, the server checks its own stored code. - Workspace resolution. The user's own workspace is used — a client-supplied tenant id is never accepted. Super-admin-only accounts with no workspace are rejected (
NO_WORKSPACE). - Subscription gate.
TenantSubscriptionStatemust be active or the API answersWORKSPACE_INACTIVE: "This workspace is not active. Renew the subscription to use the app." - Device token issued.
issueDeviceToken()creates aDevicerow and mints a 64-character device token with a 90-day TTL. The app stores it and sends it asAuthorization: Bearer …on every subsequent mobile API call.
Email/password alternative Not every workspace enables OTP. email_password_enabled and phone_password_enabled allow classic credentials; the same workspace resolution and device-token steps follow. See How mobile login finds your workspace.
Troubleshooting notes
| Symptom | Likely cause | Fix |
|---|---|---|
| OTP never arrives (phone) | Firebase quota hit, number format wrong, or Firebase phone auth not enabled | Check the number is in international format; review Firebase usage; try the SMS fallback configuration |
| OTP never arrives (email) | Tenant SMTP broken | Email & SMTP; check spam |
otp_unavailable response |
The workspace has that method disabled, or no provider configured | Enable the method / configure SMS or Firebase in workspace settings |
| "Too many attempts" | Rate limits (3 per identifier / 10 per IP per 10 min) or 5 verify tries used | Wait 10 minutes and retry |
| Code always "invalid" | App clock skew or stale code after multiple starts | Request one fresh code and enter it promptly |
| Login works but API calls fail later | Device token expired (90-day TTL) or the device was revoked | Sign in again to mint a new token |
Firebase OTP vs Firebase push are separate features OTP uses Firebase Authentication; push notifications use Firebase Cloud Messaging and are optional per workspace (How push notifications work). Configuring one does not configure the other.
Related guides
Was this page helpful?
Thanks — noted. ✦