Skip to main content

Implements Django Admin OTP Auth

Project description

django-admin-otp

Lightweight MFA (TOTP) for Django Admin: enable/disable MFA directly from the admin, verify codes on login, and support "trusted devices" via secure cookies.


Features

  • 🔑 TOTP-based MFA for Django Admin (Google Authenticator, Authy, etc.)
  • 🛠 Setup MFA from the admin panel (QR code + code entry)
  • ❌ Disable MFA with code confirmation
  • 💻 Trusted devices: skip MFA for up to N days
  • ⚙️ Middleware-based enforcement for admin access
  • 📦 Configurable via environment variables
  • 🎨 Ready-to-use templates for verification and setup pages

Installation

pip install django-admin-otp

Quickstart

Add this code to settings.py

# settings.py
INSTALLED_APPS = [
    # ...
    "django.contrib.admin",
    "django_admin_otp",
]

MIDDLEWARE = [
    # ...
    "django_admin_otp.middleware.AdminOTPMiddleware",
]

ADMIN_OTP_PROJECT_NAME = "Your-project-name"

Run migrations and createsuperuser (if it hasn't created yet):

python manage.py migrate django_admin_otp
&
python manage.py createsuperuser

Run server

python manage.py runserver

How to setup OTP

Go to localhost:8000/admin/, login to panel and go to OTP Verifications panel Setup MFA First Step Click on 'Setup MFA for current user' Setup MFA Second Step Scan QR and enter code from your app here. Click on submit. Setup MFA Third Step If code is correct - MFA for your user would be set. You will be redirected to Django Auth Form (via logout). Now you can start login process.


OTP Login process

Login into admin panel. After success - you will see theese form. Login First Step Enter code to from your app and choose trust device option. If would set - you can login from this device without MFA process. (stored in cookie). It would worked for some time (see Configuration section).


How to disable

Go to OTPVerification admin panel. Disconnect MFA First Step If you have already connected to MFA - the button would be "Disable MFA for Current user" Disconnect MFA Second Step Click on it, enter code from your app and your mfa (with trusted devices) would be deleted. Disconnect MFA Third Step


Configuration

Configurable environment variables:

  • ADMIN_OTP_PROJECT_NAME - project name which would display in Auth APP.
  • ADMIN_PATH_PREFIX — admin URL prefix (default "/admin"). Used for cases when your admin app is behind proxy
  • ADMIN_OTP_FORCE (int) — require MFA setup for all admin users (default 0). See Force OTP section for more details.
  • ADMIN_OTP_TRUSTED_DEVICE_DAYS — validity period for trusted devices (defaults 30 days)
  • ADMIN_OTP_DEVICE_TOKEN_COOKIE_NAME — name of trusted device cookie (default "admin_otp_trusted_device").

FORCE OTP

This parameter change default setup mfa behavior. If is set, all users that tries to login into admin panel would be redirected to setup mfa process. Without set mfa - you wouldn't be able to login in admin panel. How it goes: After login you'll see this form Force OTP First Step After setup mfa - you will be redirected on login to OTP process form Login First Step


How to contribute

...


How to develop


How to test

...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_admin_otp-0.1.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_otp-0.1.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_otp-0.1.0.tar.gz.

File metadata

  • Download URL: django_admin_otp-0.1.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.9 CPython/3.13.7 Linux/6.11.0-1018-azure

File hashes

Hashes for django_admin_otp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1cbb4f73127f946c1c235ae11aa01871f6204b4086769498c8427e15fa33e57a
MD5 370c8822c0aef299c003984295eb8290
BLAKE2b-256 451b52e49ac32a343460eb0fa069b773d145d92c9ccea45bd46364f4b9623dae

See more details on using hashes here.

File details

Details for the file django_admin_otp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_admin_otp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.9 CPython/3.13.7 Linux/6.11.0-1018-azure

File hashes

Hashes for django_admin_otp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c302dd3ad76181ea038749be1a8fb251dbe677c6f7243f46f722d3ce5888586b
MD5 2b1fad11aacf6522479d71590b897078
BLAKE2b-256 f8465b8b943b819e8e4237e030480909b7be8a175afd16d2897c8c7d06ca02f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page