50 - TOTP Configuration
Overview
Architecture Diagram
┌──────────────────────────────────────────────────────────────────────────────┐
│ TOTP Configuration Architecture │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ TOTP Setup Flow │
│ │
│ Step 1: Generate Secret │
│ ───────────────────────── │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ User requests 2FA setup │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ Generate base32 secret (160 bits) │ │
│ │ JBSWY3DPEHPK3PXP... │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ Generate provisioning URI │ │
│ │ otpauth://totp/OpenAlgo:[email protected]?secret=...&issuer=OpenAlgo│ │
│ │ │ │ │
│ │ ▼ │ │
│ │ Generate QR code image │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ Step 2: User Scans QR Code │
│ ───────────────────────────── │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌───────────────────┐ Scan with ┌──────────────┐ │ │
│ │ │ ████████████████ │ ───────────────► │ Authenticator│ │ │
│ │ │ █ █ │ │ App │ │ │
│ │ │ █ QR CODE █ │ │ │ │ │
│ │ │ █ █ │ │ 123456 │ │ │
│ │ │ ████████████████ │ │ ────── │ │ │
│ │ └───────────────────┘ │ 29 sec │ │ │
│ │ └──────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ Step 3: Verify and Enable │
│ ────────────────────────── │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ User enters code from app │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ Verify code against secret │ │
│ │ │ │ │
│ │ ├──► Valid: Enable TOTP, store encrypted secret │ │
│ │ │ │ │
│ │ └──► Invalid: Show error, allow retry │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘Database Schema
TOTP Fields in users Table
TOTP Implementation
Secret Generation
QR Code Generation
Code Verification
Secret Encryption
Backup Codes
Generation
Usage
API Endpoints
Initialize TOTP Setup
Enable TOTP
Disable TOTP
Verify TOTP (Login)
Login Flow with TOTP
Implementation
Frontend Components
TOTP Setup Component
TOTP Login Component
Security Considerations
Aspect
Implementation
Key Files Reference
File
Purpose
Last updated