OTP Authentication Service
A standalone TOTP microservice with origin-based multi-tenancy, database-driven CORS, and fully configurable DDoS protection — all without touching your passwords or sessions.
⚡ Integration Flow
- Generate TOTP secrets & QR codes per origin
- Verify 6-digit codes at login
- Enable and disable TOTP per user
- Prevent replay attacks automatically
- Block unknown origins at the CORS level
- Authenticate users with email + password
- Issue JWTs or sessions after login
- Send requests with the correct Origin header
- Pass tempToken = base64(email) to verify
- Add your domain to allowed_origins table
📷 How to Scan the QR Code
qrCode (base64 PNG data URI) and secret for manual entry. Render as: <img src="{qrCode}"/>Authy → + → Scan QR Code
Microsoft Authenticator → + → Other account
1Password → Edit item → Add one-time password field → scan QR
Aegis → + → Scan QR code
secret value instead.POST /auth/totp/verify-setup. On success, TOTP is active for this (email, origin) pair.📱 Recommended Authenticator Apps
All standard TOTP apps (RFC 6238) are compatible. These are the most widely used and trusted options:
/admin/tokens. See docs →📋 Endpoints
Generates a TOTP secret + QR code. Auto-creates the user (email, origin) if they don't exist. The origin is taken from the request Origin header — not the body.
| Name | Type | Required | Source | Description |
|---|---|---|---|---|
| Authorization | string | required | header | Bearer <token> — API token created via /admin/tokens. |
| string | required | body | User email — shown as the account label in the authenticator app. | |
| Origin | string | required | header | Set automatically by the browser. Must be in allowed_origins. Stored on the user record for multi-tenancy. |
Confirms the user scanned the QR. TOTP is only active after this succeeds. Lookup is by (email, origin).
| Name | Type | Required | Source | Description |
|---|---|---|---|---|
| Authorization | string | required | header | Bearer <token> — API token created via /admin/tokens. |
| string | required | body | User email. | |
| token | string | required | body | 6-digit code currently shown in the authenticator app. |
| Origin | string | required | header | Sent automatically by browser. |
tempToken = base64(email). Generated server-side after your password check. JS: btoa(email). PHP: base64_encode($email).
| Name | Type | Required | Source | Description |
|---|---|---|---|---|
| Authorization | string | required | header | Bearer <token> — API token created via /admin/tokens. |
| tempToken | string | required | body | Base64-encoded email. Produced server-side after successful password check. |
| token | string | required | body | 6-digit TOTP code from the user's authenticator app. |
| Origin | string | required | header | Sent automatically by browser. Scopes user lookup to this origin. |
Disables TOTP on the (email, origin) account. Requires a valid current code to prevent unauthorised removal.
| Name | Type | Required | Source | Description |
|---|---|---|---|---|
| Authorization | string | required | header | Bearer <token> — API token created via /admin/tokens. |
| string | required | body | User email. | |
| token | string | required | body | Current 6-digit TOTP code to confirm this action. |
| Origin | string | required | header | Sent automatically by browser. |