From 18696f4fea8f35ebe7f618ce4a8ae9d370ab8056 Mon Sep 17 00:00:00 2001 From: Bishwas Praveen Date: Tue, 23 Jan 2024 11:20:45 -0600 Subject: [PATCH 1/4] added necessary requirements --- requirements/base.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/base.txt b/requirements/base.txt index ef72e942..4e9686b5 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -29,3 +29,4 @@ scrapy==2.11.0 tqdm==4.65.0 xmltodict==0.13.0 django-cors-headers==4.3.1 +djangorestframework-simplejwt==5.3.1 From e0260518f9d657887878dd9fa51b0b67f4fd640d Mon Sep 17 00:00:00 2001 From: Bishwas Praveen Date: Tue, 23 Jan 2024 11:22:09 -0600 Subject: [PATCH 2/4] added jwt based settings to the file --- config/settings/base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/settings/base.py b/config/settings/base.py index 0ab1b206..c49a0379 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -75,6 +75,7 @@ "django_celery_beat", "rest_framework_datatables", "rest_framework", + "rest_framework_simplejwt.token_blacklist", ] CORS_ALLOWED_ORIGINS = [ @@ -333,6 +334,9 @@ "DEFAULT_PAGINATION_CLASS": "rest_framework_datatables.pagination.DatatablesPageNumberPagination", "PAGE_SIZE": 50, "EXCEPTION_HANDLER": "sde_indexing_helper.utils.exceptions.custom_exception_handler", + "DEFAULT_AUTHENTICATION_CLASSES": ( + "rest_framework_simplejwt.authentication.JWTAuthentication", + ), } GITHUB_ACCESS_TOKEN = env("GITHUB_ACCESS_TOKEN") From 172450eb3ae929f57a05890e8afaae16a8eac7a6 Mon Sep 17 00:00:00 2001 From: Bishwas Praveen Date: Tue, 23 Jan 2024 11:23:07 -0600 Subject: [PATCH 3/4] added url endpoints for token generation --- feedback/urls.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/feedback/urls.py b/feedback/urls.py index 63ee219c..500cbf39 100644 --- a/feedback/urls.py +++ b/feedback/urls.py @@ -1,4 +1,5 @@ from django.urls import path +from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView from .views import ContactFormModelView, ContentCurationRequestView @@ -10,4 +11,12 @@ ContentCurationRequestView.as_view(), name="content-curation-request-api", ), + path( + "contact-us-api/token/", TokenObtainPairView.as_view(), name="token-obtain-pair" + ), + path( + "content-curation-request-api/token/refresh/", + TokenRefreshView.as_view(), + name="token-refresh", + ), ] From 24279ee55b9aca2f781ddc6237fbf0e2c5a769a1 Mon Sep 17 00:00:00 2001 From: Bishwas Praveen Date: Tue, 23 Jan 2024 11:23:34 -0600 Subject: [PATCH 4/4] added permission classes to views --- feedback/views.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/feedback/views.py b/feedback/views.py index 6e4b0174..592bc8be 100644 --- a/feedback/views.py +++ b/feedback/views.py @@ -1,4 +1,5 @@ from rest_framework import generics +from rest_framework.permissions import IsAuthenticated from .models import ContentCurationRequest, Feedback from .serializers import ContentCurationRequestSerializer, FeedbackSerializer @@ -7,8 +8,10 @@ class ContactFormModelView(generics.CreateAPIView): queryset = Feedback.objects.all() serializer_class = FeedbackSerializer + permission_classes = [IsAuthenticated] class ContentCurationRequestView(generics.CreateAPIView): queryset = ContentCurationRequest.objects.all() serializer_class = ContentCurationRequestSerializer + permission_classes = [IsAuthenticated]