Install & Compatibility
Where this runs
tested against v10.6.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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 108.5MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 7.6s · import 0.000s · 111MB
111MB installed
● package 111MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
JwtCookieAuthentication
✓ from edx_rest_framework_extensions.auth.jwt.authentication import JwtCookieAuthentication
✗ from edx_rest_framework_extensions.auth.jwt.authentication import JwtCookieAuthentication
This quickstart demonstrates how to apply `JwtCookieAuthentication` to a Django REST Framework ViewSet, allowing JWT-based authentication via cookies. It also shows how the `exception_handler` can be used (typically configured in `settings.py`) to provide consistent error responses. The `cause_handled_error` action simulates an exception that would be processed by the custom handler.
import os
from rest_framework import viewsets, status
from rest_framework.response import Response
from rest_framework.decorators import action
from django.http import Http404
# Ensure these imports are correct for your installed version
from edx_drf_extensions.auth.jwt.authentication import JwtCookieAuthentication
from edx_drf_extensions.exception_handler import exception_handler
# In a Django settings.py file, you'd typically configure DRF:
# REST_FRAMEWORK = {
# 'DEFAULT_AUTHENTICATION_CLASSES': [
# 'edx_drf_extensions.auth.jwt.authentication.JwtCookieAuthentication',
# 'rest_framework.authentication.SessionAuthentication',
# ],
# 'EXCEPTION_HANDLER': 'edx_drf_extensions.exception_handler.exception_handler'
# }
class MyTestViewSet(viewsets.ViewSet):
"""A simple DRF view demonstrating edx-drf-extensions authentication."""
authentication_classes = [JwtCookieAuthentication]
# Permission classes would typically be added here, e.g., IsAuthenticated
def list(self, request):
if request.user.is_authenticated:
return Response({"message": f"Hello {request.user.username}, authenticated via JWT!"}, status=status.HTTP_200_OK)
return Response({"message": "Authentication failed."},
status=status.HTTP_401_UNAUTHORIZED)
@action(detail=False, methods=['get'])
def cause_handled_error(self, request):
"""Endpoint to demonstrate the custom exception handler."""
# This error will be caught by DRF's exception handling, if configured.
raise Http404("The requested resource was not found. (Handled by edx-drf-extensions)")
print("Quickstart code demonstrates applying JwtCookieAuthentication to a DRF ViewSet.")
print("It also hints at configuring the custom exception_handler in settings.py.")
print("To run fully, integrate into a Django/DRF project and configure REST_FRAMEWORK.")
Debug
Known issues
breakingPython 3.8 support was dropped in version 10.4.0. Projects using older Python versions must upgrade their environment or stick to `edx-drf-extensions < 10.4.0`.fixUpgrade your Python environment to 3.9 or higher, or pin `edx-drf-extensions` to a version prior to 10.4.0.
affects: >=10.4.0
breakingThe behavior of JWT authentication changed significantly in v10.0.0, making 'forgiving JWTs' the default. This means JWTs that fail verification due to expiry or other issues might be silently ignored if another authentication method succeeds, which could alter security assumptions.fixReview your authentication backend configuration and `edx-drf-extensions` settings. If you rely on strict JWT validation, ensure it's explicitly enforced, or adjust your system's authentication flow to account for 'forgiving' behavior.
affects: >=10.0.0
gotchaThere were several changes, reverts, and fixes related to JWT vs session user checks around versions 9.1.0-9.1.2. Upgrading between these minor versions, or to/from 10.0.0, could lead to unexpected authentication behavior or regressions.fixThoroughly test authentication after upgrading, especially if your application relies on both JWT and session authentication. Refer to the specific changelogs for each version for detailed behavioral changes.
affects: 9.1.0-10.1.0
gotchaVersion 10.6.0 added support for Django 5.2. If you are using an older version of `edx-drf-extensions` with Django 5.x, you may encounter compatibility issues or `DeprecationWarnings` from Django. Older `edx-drf-extensions` versions are not guaranteed to support newer Django releases.fixEnsure your `edx-drf-extensions` version is compatible with your Django version. Upgrade to the latest `edx-drf-extensions` (10.6.0+) if using Django 5.2.
affects: <10.6.0 with Django >=5.0
Upgrade
Version history
10.6.0latest on PyPI · released Apr 4, 2025
Audit
Dependencies
DjangorequiredCore framework dependency for any Django application.
djangorestframeworkrequiredThe library extends Django REST Framework; it is a fundamental dependency.