Skip to main content

Auth0 Authentication Backend for Django

Project description

django-auth0-auth

Authentication backend for Django with Auth0. As of June 2025, all of the libraries that I saw for Django Auth0 target old versions of Django, we'll start this by supporting version 5+ and python 3.11+ (3.10 only has 1 year of life). Also, some of these don't actually subclass Django's AuthBackend{.verbatim} and implement a login system that is more "beside" Django than integrated with it. Because this is fully integrated, we can use Django's built-in @login_required{.verbatim} decorator and it's auth Mixins.

This project is not affiliated with Auth0.

The names are slightly confusing because there are a lot of one-off projects (like this one) on PyPI that attempt the same thing. The repo name here is django-auth0-auth{.verbatim}, the pypi name is django-auth0-authbackend{.verbatim}, and the importable package is auth0{.verbatim}. The installation instructions below reflect these names.

Installation

Install the package from PyPI:

pip install django-auth0-authbackend

Usage

Take a look at the sample app provided in sample/{.verbatim} to see how it's used in a MWE. There are only a few steps. First, include the app in your apps in your Django settings:

INSTALLED_APPS = [
    ...,
    "auth0",
]

Next, include the auth settings and auth backend (also in your Django settings):

AUTH0_CLIENT_ID = os.environ.get("AUTH0_CLIENT_ID")
AUTH0_CLIENT_SECRET = os.environ.get("AUTH0_CLIENT_SECRET")
AUTH0_DOMAIN = os.environ.get("AUTH0_DOMAIN")
AUTH0_AUDIENCE = os.environ.get("AUTH0_AUDIENCE")

AUTHENTICATION_BACKENDS = [
    "auth0.backend.Auth0Backend",
]

Finally, include the urls in your project urls.py{.verbatim}:

from django.urls import path, include

urlpatterns = [
    ...,
    path("auth0/", include("auth0.urls")),
]

Running the sample app

First, create an auth0 application.

Set up python however you prefer, I'll use a virtual env:

~/.pyenv/versions/3.11.10/bin/python -m venv .venv
source .venv/bin/activate
pip install .

Running the sample app, we can do:

export AUTH0_CLIENT_ID=...
export AUTH0_CLIENT_SECRET=...
export AUTH0_DOMAIN=...
export AUTH0_AUDIENCE=...
python manage.py migrate
python manage.py runserver

Go to http://localhost:8000/auth0 and log in!

Next steps

  • Test that it works with the sample app (create an auth0 account to test)
  • Run through genAI to look for general improvements: is all the logic we have in the views/index the right place for this?
  • Add pre-commit code checks
  • Add automated release via github action
  • Flesh out user documentation here in README
  • Add automated tests
  • Profit

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_auth0_authbackend-0.0.7.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

django_auth0_authbackend-0.0.7-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file django_auth0_authbackend-0.0.7.tar.gz.

File metadata

File hashes

Hashes for django_auth0_authbackend-0.0.7.tar.gz
Algorithm Hash digest
SHA256 0b3f14f90950815286af31c00032b7507fd61466adf88792f040666608001cc3
MD5 7c8af8c78fd2c2d43f2bb660e8206bd3
BLAKE2b-256 fa02cc9d9bc5eed33add03422c4ede28e1f9aa7bd0c903450ca2c1030c06e868

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_auth0_authbackend-0.0.7.tar.gz:

Publisher: python-test-publish.yml on andyreagan/django-auth0-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_auth0_authbackend-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for django_auth0_authbackend-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1a36f952432d8a5e95865471051193719c0ff77792d4cc9dddceb2f57aa75d04
MD5 42adceee8b700f5dbb4aa9466d6bab6f
BLAKE2b-256 e03739dc1518be28b0bfab2d0752d4180acbc188b4f2a1d9f7870b48fbaf5bd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_auth0_authbackend-0.0.7-py3-none-any.whl:

Publisher: python-test-publish.yml on andyreagan/django-auth0-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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