Two-Fast-Auth¶
two-fast-auth is a FastAPI middleware for simplified 2FA implementation. It integrates seamlessly with FastAPI to offer robust protection against various security threats, ensuring your application remains secure and reliable.
Features¶
- QR Code Generation
- TOTP Verification
- Recovery Codes Generation
- Optional Secret Encryption
Quick Start¶
from fastapi import FastAPI
from two_fast_auth import TwoFactorMiddleware
app = FastAPI()
# Without encryption:
app.add_middleware(
    TwoFactorMiddleware,
    get_user_secret_callback=lambda uid: "secret",  # Plaintext secret
    excluded_paths=["/docs"]
)
# With encryption:
app.add_middleware(
    TwoFactorMiddleware,
    get_user_secret_callback=lambda uid: "encrypted_secret",
    encryption_key="your-32-url-safe-base64-key",
    excluded_paths=["/docs"]
)