Skip to main content

django-auth-headless

Reusable Django authentication built on django-allauth Headless.

The first release focuses on Google OAuth, session authentication, CSRF/CORS configuration, and setup and verification commands. The package is designed for Django projects using any browser frontend. It does not include a frontend or example application.

The original learning project, including its React frontend, is available at https://github.com/bella-247/DjangoOAuth.

Install

pip install django-auth-headless
# or
uv add django-auth-headless

The package requires Django 6.1, django-allauth with the headless and socialaccount extras, django-cors-headers, and python-dotenv.

Configure Django

In settings.py, import the package settings from django_auth_headless.conf and assign them to the corresponding Django settings:

from django_auth_headless.conf import *

Keep project-specific SECRET_KEY, DEBUG, DATABASES, TEMPLATES, ROOT_URLCONF, WSGI_APPLICATION, STATIC_URL, ALLOWED_HOSTS, and email settings in your project.

The exported INSTALLED_APPS already includes django_auth_headless, so Django discovers the package and its management commands. Do not add it a second time.

Add the package URLs to your project URL configuration:

from django_auth_headless.urls import urlpatterns as auth_urlpatterns

urlpatterns = [
    *auth_urlpatterns,
]

Run migrations after installing and configuring the package:

python manage.py migrate

Environment

Create a .env file beside manage.py:

DJANGO_FRONTEND_URL=http://localhost:5173
DJANGO_CORS_ALLOWED_ORIGINS=http://localhost:5173
DJANGO_CSRF_TRUSTED_ORIGINS=http://localhost:5173
DJANGO_AUTH_PROVIDERS=google
DJANGO_GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
DJANGO_GOOGLE_CLIENT_SECRET=your-client-secret

Security settings are also environment-driven:

DJANGO_SECURE_SSL_REDIRECT=False
DJANGO_SECURE_HSTS_SECONDS=0
DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS=False
DJANGO_SECURE_HSTS_PRELOAD=False
DJANGO_SESSION_COOKIE_SECURE=False
DJANGO_CSRF_COOKIE_SECURE=False
DJANGO_EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend

Use secure cookies, HTTPS redirect, HSTS, and a production email backend in production.

Management commands

The commands are available after django_auth_headless is included through the exported INSTALLED_APPS list and migrations have been applied.

Configure a provider

setup_oauth creates or updates the database-backed SocialApp, associates it with the configured Site, and can write credentials to an env file.

# Interactive
python manage.py setup_oauth

# Non-interactive
python manage.py setup_oauth \
  --provider google \
  --client-id "$DJANGO_GOOGLE_CLIENT_ID" \
  --client-secret "$DJANGO_GOOGLE_CLIENT_SECRET" \
  --domain localhost:8000

# Also update an env file
python manage.py setup_oauth --env-file .env

Options: --provider, --client-id, --client-secret, --domain, --name, and --env-file.

Verify configuration

python manage.py verify_oauth

This checks the Site, database SocialApp records, provider environment variables, and the allauth Headless configuration endpoint.

Provider credentials have one source of truth: the database SocialApp. Environment variables supply credentials to setup_oauth; they are not also registered as settings-backed provider applications.

Endpoints

The package includes:

  • /_allauth/browser/v1/ — django-allauth Headless endpoints.
  • /accounts/ — provider callback routes.
  • /api/me — authenticated current-user response.

GET /api/me returns:

{
  "status": 200,
  "data": {
    "user": {
      "id": 1,
      "username": "example",
      "email": "example@example.com"
    }
  }
}

Unauthenticated requests return HTTP 401.

Development

uv sync --group dev
uv run python manage.py test
uv build

Publishing

Releases are published to PyPI by the Publish package GitHub Actions workflow when a GitHub Release is published. Configure PyPI Trusted Publishing for the bella-247/django-auth-headless repository with:

  • Workflow: .github/workflows/publish.yml
  • Environment: pypi
  • PyPI project: django-auth-headless

Update the version in pyproject.toml, push a matching tag, and publish a GitHub Release for that tag. PyPI versions are immutable, so each release must use a new version number.

Scope

This is a Django-only package extracted from a Google OAuth learning project. Provider configuration is extensible, but Google OAuth is the documented and tested browser flow. The learning project is kept separate as an example.

Metadata

Release files for django-auth-headless 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-headless 0.1.0
File Size Uploaded Provenance Actions
django_auth_headless-0.1.0.tar.gz 39.4 kB With provenance Details for django_auth_headless-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 52.5 kB

Release files / django_auth_headless-0.1.0.tar.gz

Download URL django_auth_headless-0.1.0.tar.gz
Size 39.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8fe6edfb818fc6b3b986d2ad8a8a12f97aedbc74827a8d6bcab8d4798dd58cf0
BLAKE2b-256 checksum
How to use checksums
e87a1f6a9b458a277fb725a36e957461deb8ca783883a34c97a8a2ba652c2601
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

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

Download URL django_auth_headless-0.1.0-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd051b0414d3a52a26de65cabe88b6ce11d4054bb867cd0c0c8d46a81dbf0934
BLAKE2b-256 checksum
How to use checksums
fca7a85cc77126db0008847f87e947f893681266580b3389222151e6f96a83da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Security for django-auth-headless 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_auth_headless-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

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 Full 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