From a2bc1b5196839fd121bc94364a99d0ba13d6ee31 Mon Sep 17 00:00:00 2001 From: David Gunter Date: Tue, 6 Jun 2017 12:28:06 -0700 Subject: [PATCH] Add proper DRF Authentication classes to user authenticated endpoint --- rest_auth/tests/test_api.py | 1 + rest_auth/views.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rest_auth/tests/test_api.py b/rest_auth/tests/test_api.py index 3cb6ea4..e94ece8 100644 --- a/rest_auth/tests/test_api.py +++ b/rest_auth/tests/test_api.py @@ -498,6 +498,7 @@ class APITestCase1(TestCase, BaseAPITestCase): user = get_user_model().objects.create_user(self.USERNAME, self.EMAIL, self.PASS) self._login() + self.token = self.response.json['key'] self.get(self.user_authenticated_status_url, status_code=200) self.assertTrue(self.response.json['authenticated']) diff --git a/rest_auth/views.py b/rest_auth/views.py index 454b450..2479f25 100644 --- a/rest_auth/views.py +++ b/rest_auth/views.py @@ -14,6 +14,7 @@ from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.generics import GenericAPIView, RetrieveUpdateAPIView from rest_framework.permissions import IsAuthenticated, AllowAny +from rest_framework.authentication import SessionAuthentication, TokenAuthentication from .app_settings import ( TokenSerializer, UserDetailsSerializer, LoginSerializer, @@ -160,11 +161,11 @@ class UserAuthenticationStatusView(APIView): Returns True/False indicator for if user is authenticated. """ - authentication_classes = () + authentication_classes = (TokenAuthentication,) permission_classes = () def get(self, request, *args, **kwargs): - if hasattr(request, "user") and request.user.is_authenticated: + if hasattr(self.request, "user") and self.request.user.is_authenticated: return Response( {"authenticated": True}, status=status.HTTP_200_OK ) @@ -173,6 +174,7 @@ class UserAuthenticationStatusView(APIView): {"authenticated": False}, status=status.HTTP_401_UNAUTHORIZED ) + class PasswordResetView(GenericAPIView): """ Calls Django Auth PasswordResetForm save method.