Skip to main content

Django Next Auth Adapter

Django Next Auth Adapter is a Django package designed to handle server-side requests from the "next-auth-http-adapter" JavaScript package. This package is intended for use with Next.js and NextAuth.js to seamlessly integrate custom backend functionality into the NextAuth.js authentication flow by facilitating HTTP communication between the frontend and backend.

Pre-requisites

User Model

add the following to your user model

class User(AbstractBaseUser):
    # ...
    email_verified = models.DateTimeField(blank=True, null=True)
    # ...
    EMAIL_FIELD = "email"
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']
    # ...

Installation

You can install the package via pip:

pip install django-next-auth-adapter

Configuration

To configure the Django Next Auth Adapter, you need to define certain settings in your Django project's settings module (settings.py).

Include django_next_auth_adapter in your INSTALLED_APPS:

# settings.py

INSTALLED_APPS = [
    # Your other installed apps
    "django_next_auth_adapter",
]

For custom configuration, add the following settings to your settings.py file:

# settings.py

DJANGO_NEXT_AUTH_ADAPTER = {
    # optional: specify the permission classes applied to views within the package. Customize these classes as needed to control access to your views. Do not specify this parameter if you want to use the default permission classes.
    "PERMISSION_CLASSES": [
        # Add your permission classes here
    ],
    # optional: specify the token used for authenticating requests from the next-auth server. If not provided, authentication will be bypassed.
    "REMOTE_AUTH_TOKEN": "your-remote-auth-token",
}

Available Settings

  • DJANGO_NEXT_AUTH_ADAPTER (dictionary): The main configuration dictionary for the package.
    • PERMISSION_CLASSES (list): This is a list of permission classes applied to views within the package. Customize these classes as needed to control access to your views.
    • REMOTE_AUTH_TOKEN (string, optional): The token used by the default permission class for authenticating requests from the next-auth server. If not provided, authentication will be bypassed.

Usage

To use the Django Next Auth Adapter, import it as follows:

from django_next_auth_adapter import DjangoNextAuthAdapter

You can then use the imported classes and functions to handle authentication and authorization as needed within your Django views.

Configuration in urls.py

To include the package's URLs in your Django project, follow these steps:

  1. Open your project's base urls.py file.

  2. Import the package's views and include them in your URL patterns.

# urls.py

from django.urls import path, include
from django_next_auth_adapter.views import YourViewName1, YourViewName2  # Import your views here

urlpatterns = [
    # Your other URL patterns
    path('next-auth/', include('django_next_auth_adapter.urls')),  # Include the package's URLs here
]

Signals

The package provides the following signals that you can use to customize the authentication and authorization process:

  • user_created: Sent when a new user is created. The signal sends the following arguments:
    • sender: The serializer class.
    • user: The user instance.
    • validated_data: The validated data used to create the user.
    • image: The image url of the user.
    • name: The name of the user.
  • user_updated: Sent when a user is updated. The signal sends the following arguments:
    • sender: The serializer class.
    • user: The user instance.
    • validated_data: The validated data used to create the user.
    • image: The image url of the user.
    • name: The name of the user.

License

This project is open source and is licensed under the MIT License.

Metadata

Release files for django-next-auth-adapter 0.0.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 django-next-auth-adapter 0.0.4
File Size Uploaded
django-next-auth-adapter-0.0.4.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-next-auth-adapter 0.0.4
File Interpreter ABI Platform
django_next_auth_adapter-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / django-next-auth-adapter-0.0.4.tar.gz

Download URL django-next-auth-adapter-0.0.4.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d9f370a39e9563c5e4131fa14cc40726c787c2813ca35c662858123c58b21f89
BLAKE2b-256 checksum
How to use checksums
26e8e8af94c60ceaf8e3fa086732eb4d921401e557fc808eba5d43b17ea4ab6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / django_next_auth_adapter-0.0.4-py3-none-any.whl

Download URL django_next_auth_adapter-0.0.4-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93dbf27c7d39fd1431ba08c68e5f3651d594a6173f980074a74fb4429151bc26
BLAKE2b-256 checksum
How to use checksums
79f4dfd579e82c55ffe6d2a9b0aed2d8f2a4878afce2bcfdd3769ebb10b49a9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.1

2 release files

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