OTPdoor is a Python library for creating and managing OTP (One-Time Password) authentication with nginx.
Project description
OTPdoor
OTPdoor is a premium, lightweight Python library for creating and managing TOTP (One-Time Password) authentication, specifically designed to be used as an auth_request backend for Nginx.
It provides a modern, glassmorphic UI for user login and a dedicated configuration portal for initial setup and device provisioning.
Features
- Multi-Domain Support: Protect multiple independent applications with a single OTPdoor instance, each with its own secret and settings.
- TOTP Authentication: Industry-standard Time-based One-Time Passwords (RFC 6238).
- Premium UI: Modern, glassmorphic design with support for Light and Dark modes.
- Runtime Configuration: Update session durations and TOTP secrets on the fly via the
/_configendpoint. - Flexible Sessions: Configure session duration in seconds, minutes, or hours.
- Security First:
- Secure, encrypted session cookies using Fernet (AES-128).
- Restricted configuration mode with explicit CLI activation and warnings.
- Safety confirmation dialogs for critical actions.
- Production Ready: Powered by Waitress, a stable production-grade WSGI server.
- Easy Provisioning: Built-in QR code generation for quick configuration with apps like Google Authenticator or Authy.
Installation
Install OTPdoor using pip:
pip install otpdoor
Quick Start
1. Initialize your secret
Run the built-in initialization to generate your first TOTP secret:
python -m otpdoor --init
2. Set Environment Variables
Configure the essential settings:
export OPTDOOR_TOTP_SECRET="YOUR_GENERATE_SECRET"
export OPTDOOR_COOKIE_SECRET="YOUR_FERNET_KEY"
3. Run the Server
Start the server on a specific host and port:
python -m otpdoor -a 127.0.0.1 -p 8080
Multi-Domain Support
OTPdoor allows you to manage multiple authentication domains. Each domain has its own secret, session duration, and theme. Configurations are persisted in optdoor_config.json.
Managing Domains
- Add a domain:
python -m otpdoor --add-domain myapp - List domains:
python -m otpdoor --list-domains
Using Domains in URLs
Access routes for a specific domain by adding the domain parameter:
http://127.0.0.1:8080/_auth?domain=myapphttp://127.0.0.1:8080/_check?domain=myapphttp://127.0.0.1:8080/_config?domain=myapp
If no domain is provided, it defaults to default.
Step-by-Step Tutorial: First Setup
1. Installation
pip install otpdoor
2. Initial Setup
python -m otpdoor --init
3. Environment Configuration
export OPTDOOR_TOTP_SECRET="YOUR_GENERATED_SECRET"
export OPTDOOR_COOKIE_SECRET="something-very-random-and-long"
4. Provisioning your Device
python -m otpdoor -c
- Open
http://127.0.0.1:8080/_config?domain=default. - Scan the QR code.
- Stop the server (
Ctrl+C).
5. Nginx Configuration (Multi-Domain)
To protect a specific app (myapp), pass the domain parameter in the proxy requests:
upstream otpdoor_backend {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name myapp.example.com;
location / {
# Pass the domain to the check endpoint
auth_request /_check;
error_page 401 = @error401;
proxy_pass http://your_app_backend;
}
location = /_check {
internal;
# Pass domain=myapp to use the correct secret
proxy_pass http://otpdoor_backend/_check?domain=myapp;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}
location /_auth {
# Pass domain=myapp so the login page uses the correct configuration
proxy_pass http://otpdoor_backend/_auth?domain=myapp;
proxy_set_header Host $host;
}
location @error401 {
# Redirect to the domain-specific auth page
return 302 $scheme://$http_host/_auth?domain=myapp&originator=$request_uri;
}
}
Configuration Reference
OPTDOOR_TOTP_SECRET: Shared secret for thedefaultdomain.OPTDOOR_COOKIE_SECRET: Key used to encrypt session cookies.OPTDOOR_CONFIG_FILE: Path to the JSON configuration file (default:optdoor_config.json).OPTDOOR_SESSION_DURATION: Default session duration in seconds.OPTDOOR_THEME: Default theme (darkorlight).OPTDOOR_ALLOWED_DOMAINS: Allowed domains for redirects.OPTDOOR_COOKIE_SECURE: Set tofalsefor local HTTP testing.
License
MIT License - see the LICENSE file for details.
Contact
Package created with Easy-pack
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
File details
Details for the file otpdoor-0.0.10.tar.gz.
File metadata
- Download URL: otpdoor-0.0.10.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86da0d8a742fc5a42acfd71ec65e5cdc0af3375103409cb596fbdc06f212592a
|
|
| MD5 |
d10196c49287e2218c12ba5e88ea576f
|
|
| BLAKE2b-256 |
6b56a528b6c24514efe94ab24e837b34e79dc007e88d669fd782f8ec47a3ce54
|