Skip to main content

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

  1. Add "drf_totp" to your INSTALLED_APPS setting:
INSTALLED_APPS = [
    ...
    'rest_framework',
    'drf_totp',
]
  1. Include the TOTP URLconf in your project urls.py:
path('auth/', include('drf_totp.urls')),
  1. 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 secret
  • POST /auth/otp/verify/: Verify and enable TOTP
  • GET /auth/otp/status/: Get TOTP status
  • POST /auth/otp/disable/: Disable TOTP
  • POST /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/')

# Validate TOTP
response = requests.post('/auth/otp/validate/', {
    'token': '123456'  # 6-digit TOTP token
})

License

MIT License - see LICENSE file for details.

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

drf_totp-0.1.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

drf_totp-0.1.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file drf_totp-0.1.1.tar.gz.

File metadata

  • Download URL: drf_totp-0.1.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for drf_totp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9c117508cee73547f1e83900c3751d7f7487a1c9737eda2c409546f4d172edca
MD5 2fa3f318e848c48d341e77fbab384f4b
BLAKE2b-256 afc5a177ac8a8264a2c556e00f3f43b4e48d237c949fbafe90d79fc8d1e54094

See more details on using hashes here.

File details

Details for the file drf_totp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: drf_totp-0.1.1-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

Hashes for drf_totp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b5c9f7971a2c83d144660e7d8c8dc2f6dd0c5a2b48d71ab2e4139c2f59a9bf8
MD5 1deffe60d115adf6906be9035118eb6c
BLAKE2b-256 bf7a91b1de5f3a33e9b66bd87c23e6988be74b5cab056ff70f8cfc844dee8e5d

See more details on using hashes here.

Supported by

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