Django Sage Auth is a Django application designed for handling user authentication, including OTP-based (One-Time Password) verification, account activation via email or phone, and password reset functionality. It provides a flexible system for implementing various authentication strategies, including email, phone number, and username-based login.
- Support for multiple authentication methods: email, phone number, and username.
- OTP-based user verification for secure authentication.
- Account activation via email links or OTPs.
- Password reset via email, with support for secure token generation.
- User management with customizable authentication strategies.
- Easy integration with Django's authentication system.
-
Create a Virtual Environment:
python -m venv .venv
-
Activate the Virtual Environment:
-
On Windows:
.venv\Scripts\activate
-
On macOS/Linux:
source .venv/bin/activate
-
-
Install
django-sage-auth
:pip install django-sage-auth
-
Initialize Poetry (if not already initialized):
poetry init
-
Install
django-sage-auth
:poetry add django-sage-auth
-
Apply Migrations:
After installation, make sure to run the following commands to create the necessary database tables:
python manage.py makemigrations python manage.py migrate
Add django-sage-auth
to your INSTALLED_APPS
in the Django settings and configure the authentication methods and OTP settings:
INSTALLED_APPS = [
# other packages
"sage_auth",
]
# Configure the authentication methods
AUTHENTICATION_METHODS = {
"EMAIL_PASSWORD": True,
"PHONE_PASSWORD": True,
"USERNAME_PASSWORD": True,
}
# Configure the OTP settings
OTP_LOCKOUT_DURATION = 3 # in minutes
OTP_MAX_FAILED_ATTEMPTS = 4
Add the URL patterns for Django Sage Auth to your project's urls.py
:
from django.urls import path, include
urlpatterns = [
path('auth/', include('sage_auth.urls')),
# other paths
]
To activate an account via email:
- Register a user with an inactive account.
- The user receives an email with an activation link or OTP.
- The user follows the link or enters the OTP to activate their account.
To verify a user using OTP:
- Generate an OTP for the user via email or SMS.
- The user enters the OTP on the verification page.
- If the OTP is valid, the user's account is activated.
To reset a user's password:
- The user requests a password reset.
- An email with a password reset link is sent to the user.
- The user follows the link and sets a new password.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please follow the guidelines in the CONTRIBUTING.md
file when submitting a pull request.
For support, please open an issue on the GitHub repository.