Skip to main content

Centralized authentication package that enforces a single shared Django user model across multiple projects using a common database, built with Django Allauth, DRF, and SimpleJWT.

Project description

Bunifu Django Auth

A standardized authentication framework for Django projects built on:

  • Django
  • Django Allauth
  • Django REST Framework
  • SimpleJWT

Designed for internal organizational consistency and centralized user model management.


Features

  • Email-based authentication
  • JWT access & refresh tokens
  • Token rotation & blacklisting
  • DRF-ready endpoints
  • Automatic safe default configuration
  • Pluggable and override-friendly
  • Production-ready test suite (pytest + factoryboy)

Installation

using uv or pip

uv add bunifu-django-auth
---------------------
pip install bunifu-django-auth 

Quick Start

Add to Installed Apps

INSTALLED_APPS = [
    "allauth",
    "allauth.account",
    "rest_framework",
    "rest_framework_simplejwt",
    "rest_framework_simplejwt.token_blacklist",
    "bunifu_django_auth",
]

Register auth user model

AUTH_USER_MODEL="bunifu_django_auth.BunifuUser"

Include URLs

from django.urls import path, include

urlpatterns = [
    path("auth/", include("bunifu_django_auth.urls")),
    # add allauth urls for the allauth paths
    path("accounts/", include("allauth.urls")),
]

Include the JWTAuthorization

REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework_simplejwt.authentication.JWTAuthentication",
    )
}

Ensure the allauth middleware is added as below

MIDDLEWARE = [
    ...
    # add this
    "allauth.account.middleware.AccountMiddleware"
]

Migrate the tables

python manage.py migrate

That’s it.

No additional configuration required.


Available Endpoints

Endpoint Method Description
/auth/register/ POST Register new user
/auth/login/ POST Obtain JWT access & refresh tokens
/auth/refresh/ POST Refresh access token
/auth/logout/ POST Blacklist refresh token

Default Configuration

The package automatically applies safe defaults:

  • Email authentication
  • JWT token rotation
  • 15-minute access tokens
  • 7-day refresh tokens
  • Refresh token blacklisting
  • DRF JWT authentication backend

All settings can be overridden in the host project.

Example:

SIMPLE_JWT = {
    "ACCESS_TOKEN_LIFETIME": timedelta(minutes=5),
}

Overriding custom user model abstract

If by any chance you want to update your user model You can simply inherit from the BunifuAbstractUser as shown below

from django.db import models
from bunifu_django_auth.models import BunifuAbstractUser

class CustomUser(BunifuAbstractUser):
    user_stats = models.JSONField(default=list)

Then in the settings

AUTH_USER_MODEL = "your_app.CustomUser"

Overriding Serializers

You may override serializers if needed:

BUNIFU_REGISTER_SERIALIZER = "yourapp.serializers.CustomRegisterSerializer"

Running Tests

pytest

With coverage:

pytest --cov=bunifu_django_auth

License

MIT License © 2026 Bunifu

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

bunifu_django_auth-0.3.3.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

bunifu_django_auth-0.3.3-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file bunifu_django_auth-0.3.3.tar.gz.

File metadata

  • Download URL: bunifu_django_auth-0.3.3.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for bunifu_django_auth-0.3.3.tar.gz
Algorithm Hash digest
SHA256 fa5079874a8523636053b1d512ac8377d115ddea750b2061617cd88298c9653b
MD5 4bdb33bac3e79b8ae5193b57e198f908
BLAKE2b-256 700e2247156e7e23c13886be34b714d99bc40fecd31c3de2b5e376ab681bcabd

See more details on using hashes here.

File details

Details for the file bunifu_django_auth-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bunifu_django_auth-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d24a9deb9ab2c907b9b68312af36590ee5bdc86c3c3e76669faabf8d2394a89d
MD5 d7c971d37a3ef7b12f2601e4922a63d5
BLAKE2b-256 c7694824f186fcb595d8ca62a8fc047c92ccffb9ad601032091fa5bc85ef3be6

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