TOTP (Time-based One-Time Password) authentication for Django REST Framework
Project description
DRF-TOTP
TOTP (Time-based One-Time Password) authentication for Django REST Framework.
Features
- Generate TOTP secrets for users
- Verify TOTP tokens
- Enable/disable TOTP authentication
- Check TOTP status
- Validate TOTP tokens
Installation
pip install drf-totp
Quick Start
- Add "drf_totp" to your INSTALLED_APPS setting:
INSTALLED_APPS = [
...
'drf_totp',
]
- Include the TOTP URLconf in your project urls.py:
path('auth/', include('drf_totp.urls')),
- Run migrations:
python manage.py migrate
Settings
Add these to your Django settings:
# Optional: Set your TOTP issuer name (defaults to "drftotp")
TOTP_ISSUER_NAME = "Your App Name"
API Endpoints
POST /auth/otp/generate/
: Generate new TOTP secretPOST /auth/otp/verify/
: Verify and enable TOTPGET /auth/otp/status/
: Get TOTP statusPOST /auth/otp/disable/
: Disable TOTPPOST /auth/otp/validate/
: Validate TOTP token
Usage Example
# Generate TOTP
response = requests.post('/auth/otp/generate/')
secret = response.json()['secret']
otpauth_url = response.json()['otpauth_url']
# Verify TOTP
response = requests.post('/auth/otp/verify/', {
'token': '123456' # 6-digit TOTP token
})
# Check Status
response = requests.get('/auth/otp/status/')
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
drf_totp-0.1.0.tar.gz
(5.2 kB
view details)
Built Distribution
File details
Details for the file drf_totp-0.1.0.tar.gz
.
File metadata
- Download URL: drf_totp-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14a6781db60b9574d0cef17c0d7011f9a846e304f8a0412ea9206b96071b7cb7 |
|
MD5 | 5f553b7f67386c2df20d3fdae2112848 |
|
BLAKE2b-256 | 3d35b3f58c180b7e5c3db41580ea4bd9951b8382aee6945e5080e1ca7b4d8659 |
File details
Details for the file drf_totp-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: drf_totp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74b2f7e36e56475e86b50629e6269ea4268748019f0c9b2679d8c091ddabe376 |
|
MD5 | c8e136bbbe05c9bdf33914f4c53f086a |
|
BLAKE2b-256 | ed6aca857e5677ccd1b3e31857c6a59677f968223bd22012253e2595b357fd17 |