Skip to main content

djangorestframework-auth0


This library let you to authenticate an specific user on DRF based on the JWT Token returned by Auth0 Javascript libraries.

Logo

Installation

  1. Using pip to install current release:
pip install rest_framework_auth0
  1. Using pip to install development version:
pip install git+https://github.com/mcueto/djangorestframework-auth0/

Quick start

  1. Make sure django.contrib.auth in on INSTALLED_APPS setting, otherwise add it by your own:
INSTALLED_APPS = [
    ...
    'django.contrib.auth',
    ...
]

This will allow us to login as an specific user as well as auto-creating users when they don't exist

  1. Add rest_framework_auth0 to your INSTALLED_APPS setting:
INSTALLED_APPS = [
    ...,
    'rest_framework_auth0',
]
  1. Add Auth0JSONWebTokenAuthentication in your DEFAULT_AUTHENTICATION_CLASSES located at settings.py from your project:
REST_FRAMEWORK = {
    ...,
    'DEFAULT_AUTHENTICATION_CLASSES': (
        ...,
        'rest_framework_auth0.authentication.Auth0JSONWebTokenAuthentication',
    ),
}
  1. Add your CLIENTS & MANAGEMENT_API settings in your settings.py file:
# Import cryptography libraries
from cryptography.x509 import load_pem_x509_certificate
from cryptography.hazmat.backends import default_backend
# Read the your Auth0 client PEM certificate
certificate_text = open('rsa_certificates/certificate.pem', 'rb').read()
certificate = load_pem_x509_certificate(certificate_text, default_backend())
# Get your PEM certificate public_key
certificate_publickey = certificate.public_key()
#
#
# AUTH0 SETTINGS
AUTH0 = {
  'CLIENTS': {
      'default': {
          'AUTH0_CLIENT_ID': '<YOUR_AUTH0_CLIENT_ID>',
          'AUTH0_AUDIENCE': '<YOUR_AUTH0_CLIENT_AUDIENCE>',
          'AUTH0_ALGORITHM': 'RS256',  # default used in Auth0 apps
          'PUBLIC_KEY': certificate_publickey',
      }
  },
  # Management API - For roles and permissions validation
  'MANAGEMENT_API': {
      'AUTH0_DOMAIN': '<YOUR_AUTH0_DOMAIN>',
      'AUTH0_CLIENT_ID': '<YOUR_AUTH0_M2M_API_MANAGEMENT_CLIENT_ID>',
      'AUTH0_CLIENT_SECRET': '<YOUR_AUTH0_M2M_API_MANAGEMENT_CLIENT_SECRET>'
  },
}
  1. Add the Authorization Header to all of your REST API request, prefixing Bearer to your token(default in common REST clients & Postman):
Authorization: Bearer <AUTH0_GIVEN_TOKEN>
  1. That's it, now only your Auth0 users can request data to your DRF endpoints
NOTE: In order to get the token authentication, the 'django.contrib.auth' app models migrations must be applied(python manage.py migrate).

Use cases

Sample Project

A sample project can be found here

Metadata

Release files for rest-framework-auth0 0.6.4

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

Source distribution (sdist)

Source distribution for rest-framework-auth0 0.6.4
File Size Uploaded
rest-framework-auth0-0.6.4.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rest-framework-auth0 0.6.4
File Interpreter ABI Platform
rest_framework_auth0-0.6.4-py3-none-any.whl Python 3 none any Details

Total release size: 26.0 kB

Release files / rest-framework-auth0-0.6.4.tar.gz

Download URL rest-framework-auth0-0.6.4.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
de1af1e7950a7397a20906c4f85503b87aa7492fc012a84ec096b1885e5bf9af
BLAKE2b-256 checksum
How to use checksums
97021846d6e6909f9547e2b388ed6a5aa36c21fa7aab3f87c03104ff9c7f081d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.7.5 Linux/5.3.0-7648-generic

Release files / rest_framework_auth0-0.6.4-py3-none-any.whl

Download URL rest_framework_auth0-0.6.4-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89707208ffcd072f6f7c4331b23eb22336f67f90075d9f56f97dc1b6c00821c2
BLAKE2b-256 checksum
How to use checksums
708f6a0f0c1ff32e8190242d110cd683449a21d342c4ad25fc9425ed691f5409
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.7.5 Linux/5.3.0-7648-generic

Release history Release notifications | RSS feed

This release

0.6.4 This release

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.6

1 release file

0.4.5

1 release file

0.4.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.1

1 release file

0.1

1 release file

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