Skip to main content

A clean Django authentication boilerplate with JWT, rate limiting, and custom exception handling.

Project description


# Django Auth Boilerplate 🔐

A simple, production-ready Django authentication boilerplate using **JWT (JSON Web Tokens)** powered by `djangorestframework-simplejwt`.

## Features

✅ JWT Authentication (access & refresh tokens)  
✅ Registration with validation  
✅ Login & Logout  
✅ Token Blacklisting  
✅ Custom Exception Handling with Logging  
✅ Throttling (Rate Limiting)  
✅ Clean project structure  
✅ Ready for PyPI packaging


---

## 📦 Installation

```bash
pip install auth-boilerplate

Or if you’re developing locally:

git clone https://github.com/Meekemma/auth-boilerplate.git
cd auth-boilerplate
pip install -r requirements.txt

⚙️ Setup Instructions

  1. Add to INSTALLED_APPS in your settings.py:
INSTALLED_APPS = [
    ...
    'rest_framework',
    'rest_framework_simplejwt.token_blacklist',
    'your_auth_app',  # Replace with your app name
]
  1. Configure Authentication & Throttling:
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
    'DEFAULT_THROTTLE_CLASSES': [
        'rest_framework.throttling.ScopedRateThrottle',
    ],
    'DEFAULT_THROTTLE_RATES': {
        'login': '3/minute',
        'register': '5/minute',
        'logout': '5/minute',
    },
    'EXCEPTION_HANDLER': 'coreuser.utils.custom_exception_handler',
}
  1. Add JWT Settings (Optional):
from datetime import timedelta

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
    'BLACKLIST_AFTER_ROTATION': True,
}

🔑 Generating a Secret Key

Run this in Python shell:

from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())

Copy the result and paste it into your .env or settings.py as:

SECRET_KEY = 'your-generated-secret-key'

📮 API Endpoints

Method Endpoint Description
POST /register/ Register a user
POST /login/ Obtain tokens (JWT)
POST /logout/ Logout & blacklist token
POST /token/refresh/ Refresh access token

🧪 Testing with Postman

Registration

{
  "first_name": "John",
  "last_name": "Doe",
  "email": "john@example.com",
  "password": "StrongPassword123!",
  "password2": "StrongPassword123!"
}

🔐 Login

{
  "email": "john@example.com",
  "password": "StrongPassword123!"
}

Response:

{
  "refresh": "your-refresh-token",
  "access": "your-access-token",
  "user": {
    "id": 1,
    "email": "john@example.com",
    "first_name": "John",
    "last_name": "Doe"
  }
}

🚪 Logout

{
  "refresh": "your-refresh-token"
}

Note: This will blacklist the token and invalidate future use.


🔄 Token Refresh

{
  "refresh": "your-refresh-token"
}

Response:

{
  "access": "new-access-token"
}


💡 Contribution

Pull requests are welcome! Please fork the repo and submit a PR with a clear description.


📝 License

This project is licensed under the MIT License.


📫 Contact


---

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_boilerplate-0.1.0.tar.gz (12.3 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_boilerplate-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file django_auth_boilerplate-0.1.0.tar.gz.

File metadata

  • Download URL: django_auth_boilerplate-0.1.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for django_auth_boilerplate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c06f9783e786ec653b0d257efd62b6b36e739b20f47b2b5d44f7efa51c5bf9bd
MD5 8336f5f608000a45bca0bd8fc16a00d1
BLAKE2b-256 00551746cf680c65812eec526b2f9d2912c363cbfd5f4a5f9420a6a6f1f50d00

See more details on using hashes here.

File details

Details for the file django_auth_boilerplate-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_auth_boilerplate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3eda69cb8f535bec711017d88009b0bcee5c5ec3ccb039446d6d5903e49770b
MD5 1c9601439dba386ad9dd665d19419cd3
BLAKE2b-256 2e14ed8c097ba2be9e4000075135602a8ac63cdedbf1becdaef0c04c9dd8483b

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