Skip to main content

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

  1. Install the package:

    pip install django-auth-app
    
  2. Add the app to your Django project:

    In your settings.py, add auth_app to your INSTALLED_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'
  1. 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'
    
  2. 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
]

  1. 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

django_auth_app-0.3.2.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_auth_app-0.3.2-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file django_auth_app-0.3.2.tar.gz.

File metadata

  • Download URL: django_auth_app-0.3.2.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for django_auth_app-0.3.2.tar.gz
Algorithm Hash digest
SHA256 11c458c50ed287dde1e0f7aead3eeeb90cefa10465156404e33d2e32aa308984
MD5 0e5fab1077257b751c660b9930d72970
BLAKE2b-256 01b47afff625f9f5d2587844f17e5d2df99c05f986dc3ff4487cd2ebe3e32e93

See more details on using hashes here.

File details

Details for the file django_auth_app-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_auth_app-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 20300fcaa370afe61beaaac7ae22e903e34384c03802f47892b16655309e3d6b
MD5 8d7f2f936c4462792202ae607081ff2d
BLAKE2b-256 f1926e8ac4167e6476fc218fd76ba0129c4d77317ccf48cdd30deaab206e30a6

See more details on using hashes here.

Supported by

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