Yet Another Implementation of One-Time-Password-Authentication for Django
Yet Another Implementation of OTP for Django
This script is "Yet Another Implementation" of 2 factor authentication.
Why I re-invent?
First, I tried Django OTP, but 2 FA code is required though it should be optional. Moreover, Admin Panel to edit/fix secret key is not provided.
How to use
- Install this script. There's pip package and you can install it by
pip install django_good_otp.
- Create a Django project as usual.
- Edit settings.py. You will need to edit INSTALLED_APPS and AUTHENTICATION_BACKENDS. For detail, refer Edit Settings section.
- Run migration as usual.
url.pyof your root URL config to enable QR Code. For details, Check out URL Routing section.
- To enable admin panel, you will need to write very small code. For details, Check out Enable Admin Panel section.
- To use 2FA on Admin panel login, you will also need to write very simple code. For details, Check out Enable Admin Panel section.
You will need to edit configuration such settings.py. The variable to edit
You will just need to add
'django.contrib.auth' i.e. it should be like this:
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', "django_otp.DjangoOTP" ]
Note that this depends on the case. i.e. If you have more apps
INSTALLED_APPS list might be longer/shorter than
To use 2 FA, you will need to replace authentication backend with the backend
this module provides. i.e. just set
("django_otp.backends.OTPAuthBackend", ). i.e. like this:
AUTHENTICATION_BACKENDS = ("django_otp.backends.OTPAuthBackend", )
This module supports QRCode to transfer Secret Key to your device. To
use it, you will need to add
from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^qr/', include("django_otp.urls")) ]
Enable Admin Panel
By default, Admin Panel of the model that stores secret key is disabled.
To enable Admin Panel, you will need to call
OTPAdmin.enable() method like
from django.conf.urls import url, include from django.contrib import admin from django_otp.admin import OTPAdmin OTPAdmin.enable() urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^qr/', include("django_otp.urls")) ]
Using 2FA form on adminsite
Unfortunately, login template of administration site doesn't handle custom
login form. Therefore, to use 2FA-ready admin form, you will need to replace
django_otp.admin.AdminSite. i.e. like this:
from django.conf.urls import url, include from django.contrib import admin from django_otp.admin import AdminSite OTPAdmin.enable() urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^qr/', include("django_otp.urls")) ]
For other stuff that is not documented here, please refer the source code.
The code is on Github and you can create issues/PRs. Making issues is appreciated, however, making PRs is more appreciated.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size django_good_otp-1.1.4.tar.gz (10.8 kB)||File type Source||Python version None||Upload date||Hashes View hashes|