Menu

Adding TOTP-Based 2FA to Django REST Framework with django-totp
🖼️

Adding TOTP-Based 2FA to Django REST Framework with django-totp

DEV Community·Kumar Sahil·7 months ago
#t9XfzHoI
#webdev#django#python#opensource#totp
Long article (549 words) — no AI summary yet.
Reading 0:00
15s threshold

Two-factor authentication (2FA) is becoming a standard requirement for modern applications, especially for APIs that use JWT authentication or separate frontend/backend architectures.

While working on Django REST Framework projects, I wanted a lightweight and API-focused way to add TOTP authentication without depending heavily on template-based flows or admin integrations.

So I built django-totp .

It is a reusable Django package that provides:

TOTP enrollment

QR generation

backup recovery codes

encrypted secret storage

DRF endpoints

helper utilities for multi-step authentication flows

PyPI: django-totp

Requirements

Python 3.12+

Django 5.0+

Django REST Framework 3.15+

Installation

Install the package from PyPI:

pip install django-totp

Enter fullscreen mode

Exit fullscreen mode

Add the apps to your Django settings:

INSTALLED_APPS = [ # Django apps...…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.