Registry / auth-security / dj-rest-auth

dj-rest-auth

JSON →
library7.2.0pypypi✓ verified 26d ago

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.

pip install dj-rest-auth
INSTALL
IMPORT
SIG · DJ-REST-AUTH
D
dj-rest-auth
auth-securitypythonv7.2.0
Install
5.5s avg
Import
—
Disk
74MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v7.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 75MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 5.5s · import 0.000s · 76MB
74MB installed
● package 74MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LoginView
✓ from dj_rest_auth.views import LoginView
✗ from dj_rest_auth.views import LoginView

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', # }
Debug
Known issues
breakingVersion 7.0.0 dropped support for Python versions older than 3.10 and Django versions older than 4.2. Ensure your environment meets these new minimum requirements.
fix
Upgrade Python to 3.10+ and Django to 4.2+ before upgrading dj-rest-auth to 7.0.0 or later.
affects: 7.0.0+
gotchaWhen using `dj-rest-auth.registration` (which depends on `django-allauth`), ensure `allauth.account.middleware.AccountMiddleware` is correctly configured and placed in your `MIDDLEWARE` settings, typically after `django.contrib.sessions.middleware.SessionMiddleware`.
fix
Add 'allauth.account.middleware.AccountMiddleware' to your MIDDLEWARE list in settings.py.
affects: All versions with django-allauth
gotchaAs of v7.1.0, email and username requirement checks for registration are primarily managed through the `SIGNUP_FIELDS` setting within the `REST_AUTH` dictionary. Relying on older methods or direct `django-allauth` settings for these might lead to unexpected behavior.
fix
Configure `REST_AUTH['SIGNUP_FIELDS']` and other `REST_AUTH` settings to explicitly define required registration fields.
affects: 7.1.0+
gotchaMulti-Factor Authentication (MFA/2FA) support, introduced in v7.2.0, is an opt-in feature. It requires installing the extra `dj-rest-auth[with_mfa]` and `django-mfa` package, and then including `dj_rest_auth.mfa` in `INSTALLED_APPS`.
fix
For MFA, ensure you `pip install "dj-rest-auth[with_mfa]"` and add `django_mfa`, `dj_rest_auth.mfa` to `INSTALLED_APPS`.
affects: 7.2.0+
gotchaThe `REST_AUTH` settings provide extensive customization options for serializers (e.g., `LOGIN_SERIALIZER`, `USER_DETAILS_SERIALIZER`). Incorrectly overriding these or using an incompatible custom serializer can break core authentication flows.
fix
Always inherit from `dj_rest_auth`'s default serializers when creating custom ones, or ensure your custom serializers conform to the expected input/output fields. Test custom serializer changes thoroughly.
affects: All versions
Upgrade
Version history
7.2.0latest on PyPI · released Mar 15, 2026
Audit
Dependencies
DjangorequiredCore framework dependency.
djangorestframeworkrequiredCore REST framework dependency.
django-allauthoptionalOptional, for registration and social authentication features.
djangorestframework-simplejwtoptionalOptional, for JWT authentication support.
django-mfaoptionalOptional, for Multi-Factor Authentication (MFA/2FA) support, introduced in v7.2.0.
Agent activity
16 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
dj-rest-auth — pip install dj-rest-auth · libregistry