A Django authentication boilerplate with OTP and role-based access control
Project description
django-auth-app
A Django authentication boilerplate with OTP and role-based access control. This package provides a robust and reusable authentication system, including basic registration, login/logout, password management, OTP setup and email verification.
Features
- Basic Authentication: Registration, login, logout, password change.
- OTP Verification: For registration and password reset.
- Email Verification: Through SMTP.
- Role-Based Access Control (RBAC): Differentiated roles for custom and social registrations.
- Swagger Documentation: API documentation.
- JWT Token Authentication: For API access.
Installation
-
Install the package:
pip install django-auth-app
-
Add the app to your Django project:
In your
settings.py, addauth_appto yourINSTALLED_APPS:INSTALLED_APPS = [ # Other installed apps 'auth_app', 'rest_framework', 'drf_yasg', ]
Set the custom user model:
This package provides a custom user model. You should update the AUTH_USER_MODEL setting:
AUTH_USER_MODEL = 'auth_app.CustomUser'
-
Configure SMTP for email sending:
Add your SMTP settings to
settings.py:EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.example.com' EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = 'your_email@example.com' EMAIL_HOST_PASSWORD = 'your_email_password'
-
Set up JWT authentication:
Add the following to
settings.py:REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.SessionAuthentication', ],
}
5. **Include the URL configurations**:
Add the following to your project's `urls.py`:
```python
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from rest_framework import permissions
schema_view = get_schema_view(
openapi.Info(
title="Authentication API",
default_version='v1',
description="API documentation for authentication features including registration, OTP verification, and password reset.",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="contact@api.local"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)
urlpatterns = [
#Other urls
path('auth/', include('auth_app.urls')), # Custom authentication URLs
path('docs/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
#Other urls
]
-
Run migrations:
python manage.py makemigrations python manage.py migrate
Usage
Web Views
- Registration:
/register/ - Login:
/login/ - Logout:
/logout/ - Password Change:
/password-change/ - Password Reset:
/password-reset/ - OTP Verification:
/otp-verify/
API Endpoints
- Register:
api/register/ - Login:
api/login/ - OTP Verify:
api/otp-verify/ - Password Change:
api/password-change/ - Password Reset:
api/password-reset/
Swagger Documentation
- Swagger UI:
/docs/
Development
To contribute to the development of django-auth-app, clone the repository and install the dependencies:
git clone https://github.com/sajan69/django-auth-boilerplate.git
cd django-auth-boilerplate
pip install -r requirements.txt
Testing
To run tests, use:
pytest
License
MIT License. See the LICENSE file for details.
Author
Sajan Adhikari
sajana46@gmail.com
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_auth_app-0.3.1.tar.gz.
File metadata
- Download URL: django_auth_app-0.3.1.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f3dc21738d5765b7d67604444ccea1e95a8202c7c2aa447c976d7b90f232798
|
|
| MD5 |
15270e6bbf2881a0cc82f12ebbd27b9e
|
|
| BLAKE2b-256 |
4705495b08b00b91d9d29cdb83cdaf7e03ddcf35034a8286ed56a54d1d76f3f9
|
File details
Details for the file django_auth_app-0.3.1-py3-none-any.whl.
File metadata
- Download URL: django_auth_app-0.3.1-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1103145aa92f35454ae0bb983648be80ca972172bfea3b8aa5b58882827be6cc
|
|
| MD5 |
0b265f30f0db8f835251b8fd1bfc9076
|
|
| BLAKE2b-256 |
e38bc904c2141778998ce9398dc71c3147c00447845b4104cdfa5b06f65222ec
|