Authentication
Two-Factor Authentication
Enable or disable two-factor authentication
POST
Enable 2FA
Endpoint
Overview
Manages two-factor authentication (2FA) using TOTP (Time-based One-Time Password). The process involves two steps for enabling: generating a QR code, then confirming with a verification code.Enable 2FA (Step 1: Generate QR Code)
Request
Must be
trueResponse
Base64-encoded PNG QR code image (data URI format)
Base32-encoded secret key for manual entry
Same as
secret (for compatibility)“Scan the QR code with your authenticator app”
Enable 2FA (Step 2: Confirm)
Request
Must be
trueSecret from Step 1 response
TOTP code from authenticator app (6 digits)
Response
“2FA enabled successfully”
Always
trueDisable 2FA
Request
Must be
falseCurrent TOTP code from authenticator app
Response
“2FA disabled successfully”
Always
falseImplementation Details
Process Flow
Enable (Step 1):- Generates secret using speakeasy (32 characters, base32)
- Creates OTPAuth URL with issuer and label
- Generates QR code as base64 data URI
- Returns QR code and secret (not saved yet)
- Verifies TOTP code with provided secret (window: 2)
- Saves secret to user record
- Sets
twoFactorEnabledto true - Logs audit event
- Verifies 2FA is enabled
- Verifies TOTP code with stored secret
- Clears secret and disables 2FA
- Logs audit event
Code Reference
Status Codes
Success
Validation error, invalid verification code, or 2FA not enabled when disabling
Missing or invalid authentication token
User not found
Example Requests
Generate QR Code
Confirm Enable
Disable 2FA
TOTP Configuration
- Algorithm: SHA1
- Digits: 6
- Period: 30 seconds
- Window: 2 (allows codes from ±1 time step)
Supported Authenticator Apps
- Google Authenticator
- Authy
- 1Password
- Microsoft Authenticator
- Any TOTP-compatible app
Security Notes
- Secret is stored in database (encrypted at rest if database encryption is enabled)
- QR code contains OTPAuth URL with issuer and email label
- Verification window of 2 allows for slight clock drift
- Secret is cleared when 2FA is disabled
- All 2FA operations are logged in audit trail
Audit Events
- TWO_FACTOR_ENABLE: 2FA enabled
- TWO_FACTOR_DISABLE: 2FA disabled
Enable 2FA