Skip to main content

# 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


---

Metadata

Release files for django-auth-boilerplate 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-auth-boilerplate 0.1.0
File Size Uploaded Provenance Actions
django_auth_boilerplate-0.1.0.tar.gz 12.3 kB Without provenance Details for django_auth_boilerplate-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-auth-boilerplate 0.1.0
File Interpreter ABI Platform Actions
django_auth_boilerplate-0.1.0-py3-none-any.whl Python 3 none any Details for django_auth_boilerplate-0.1.0-py3-none-any.whl

Total release size: 27.6 kB

Release files / django_auth_boilerplate-0.1.0.tar.gz

Download URL django_auth_boilerplate-0.1.0.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c06f9783e786ec653b0d257efd62b6b36e739b20f47b2b5d44f7efa51c5bf9bd
BLAKE2b-256 checksum
How to use checksums
00551746cf680c65812eec526b2f9d2912c363cbfd5f4a5f9420a6a6f1f50d00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / django_auth_boilerplate-0.1.0-py3-none-any.whl

Download URL django_auth_boilerplate-0.1.0-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3eda69cb8f535bec711017d88009b0bcee5c5ec3ccb039446d6d5903e49770b
BLAKE2b-256 checksum
How to use checksums
2e14ed8c097ba2be9e4000075135602a8ac63cdedbf1becdaef0c04c9dd8483b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Security for django-auth-boilerplate 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page