Installation

$ pip install django-auth-protection

How to use it

Then you have to create a custom TokenObtainPairView class and change the serializer_class to ProtectTokenObtainPairSerializer (follow the sample):

  • Make a custom TokenObtainPairView and change the serializer_class:

from auth_protection.serializers import ProtectTokenObtainPairSerializer


class CustomTokenObtainPairView(TokenObtainPairView):
    serializer_class = ProtectTokenObtainPairSerializer
  • Change All authentication_classes on your views and replace it with JWTAuthProtection:

from auth_protection.authentications import JWTAuthProtection


class SampleView(TARGET_VIEW):
    authentication_classes = [JWTAuthProtection]
  • Change your TokenRefreshView view to ProtectTokenRefreshView (EX: urls.py):

from auth_protection.views import ProtectTokenRefreshView

urlpatterns = [
    # ...
    path('YOUR_PATH/refresh/', ProtectTokenRefreshView.as_view(), name='URL_NAME'),
    # ...
]