Django REST Auth

7.2.0 · active · verified Mon Apr 13

dj-rest-auth provides a set of customizable REST API endpoints for user authentication and registration in Django REST Framework, leveraging django-allauth for extended functionality. It is actively maintained with frequent releases, currently at version 7.2.0, supporting modern Django and Python versions.

Warnings

Install

Imports

Quickstart

To integrate dj-rest-auth, first configure your `INSTALLED_APPS` and `REST_FRAMEWORK` settings in `settings.py`, including `dj_rest_auth`, `dj_rest_auth.registration`, and required `django-allauth` apps. Then, include the `dj_rest_auth` and `dj_rest_auth.registration` URLs in your project's `urls.py`. Remember to adjust `REST_AUTH` and `django-allauth` settings to suit your authentication strategy.

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api-auth/', include('rest_framework.urls')), # Optional: for browsable API
    path('dj-rest-auth/', include('dj_rest_auth.urls')), # For login, logout, password reset etc.
    path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')) # For registration
]

# In your settings.py:
# INSTALLED_APPS = [
#     # ... Django and DRF apps
#     'rest_framework',
#     'rest_framework.authtoken', # For TokenAuthentication
#     'dj_rest_auth',
#     'dj_rest_auth.registration',
#     'allauth', # Required for dj_rest_auth.registration
#     'allauth.account',
#     'allauth.socialaccount', # Optional: if using social login
#     # ... other apps
# ]
# 
# REST_FRAMEWORK = {
#     'DEFAULT_AUTHENTICATION_CLASSES': [
#         'rest_framework.authentication.SessionAuthentication',
#         'rest_framework.authentication.TokenAuthentication',
#         # 'dj_rest_auth.jwt_auth.JWTAuthentication', # If using JWT
#     ],
#     'DEFAULT_PERMISSION_CLASSES': [
#         'rest_framework.permissions.IsAuthenticated',
#     ],
# }
# 
# # django-allauth settings (required by dj_rest_auth.registration)
# ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
# ACCOUNT_EMAIL_REQUIRED = True
# ACCOUNT_EMAIL_VERIFICATION = 'optional' # or 'mandatory'
# ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE = True
# 
# # dj-rest-auth specific settings
# REST_AUTH = {
#     'USE_JWT': False, # Set to True if you installed with_jwt
#     'USER_DETAILS_SERIALIZER': 'dj_rest_auth.serializers.UserDetailsSerializer',
#     'LOGIN_SERIALIZER': 'dj_rest_auth.serializers.LoginSerializer',
#     'REGISTER_SERIALIZER': 'dj_rest_auth.registration.serializers.RegisterSerializer',
# }

view raw JSON →