Skip to main content
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

boolean
required
Must be true

Response

string
Base64-encoded PNG QR code image (data URI format)
string
Base32-encoded secret key for manual entry
string
Same as secret (for compatibility)
string
“Scan the QR code with your authenticator app”

Enable 2FA (Step 2: Confirm)

Request

boolean
required
Must be true
string
required
Secret from Step 1 response
string
required
TOTP code from authenticator app (6 digits)

Response

string
“2FA enabled successfully”
boolean
Always true

Disable 2FA

Request

boolean
required
Must be false
string
required
Current TOTP code from authenticator app

Response

string
“2FA disabled successfully”
boolean
Always false

Implementation Details

Process Flow

Enable (Step 1):
  1. Generates secret using speakeasy (32 characters, base32)
  2. Creates OTPAuth URL with issuer and label
  3. Generates QR code as base64 data URI
  4. Returns QR code and secret (not saved yet)
Enable (Step 2):
  1. Verifies TOTP code with provided secret (window: 2)
  2. Saves secret to user record
  3. Sets twoFactorEnabled to true
  4. Logs audit event
Disable:
  1. Verifies 2FA is enabled
  2. Verifies TOTP code with stored secret
  3. Clears secret and disables 2FA
  4. Logs audit event

Code Reference

Status Codes

OK
Success
Bad Request
Validation error, invalid verification code, or 2FA not enabled when disabling
Unauthorized
Missing or invalid authentication token
Not Found
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

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Response

200 - application/json

2FA enabled

secret
string
qrCode
string
backupCodes
string[]