From 6da0703b0daefcc1d569027b5d5862bda86c5ee0 Mon Sep 17 00:00:00 2001 From: Grigoriy Beziuk Date: Fri, 30 Jun 2017 13:59:10 +0300 Subject: [PATCH] LoginView.get_response modified in order to respect rest_framework_jwt.JWT_AUTH_COOKIE setting --- rest_auth/views.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rest_auth/views.py b/rest_auth/views.py index 0493a76..290c837 100644 --- a/rest_auth/views.py +++ b/rest_auth/views.py @@ -84,7 +84,17 @@ class LoginView(GenericAPIView): serializer = serializer_class(instance=self.token, context={'request': self.request}) - return Response(serializer.data, status=status.HTTP_200_OK) + response = Response(serializer.data, status=status.HTTP_200_OK) + if getattr(settings, 'REST_USE_JWT', False): + from rest_framework_jwt.settings import api_settings as jwt_settings + if jwt_settings.JWT_AUTH_COOKIE: + from datetime import datetime + expiration = (datetime.utcnow() + jwt_settings.JWT_EXPIRATION_DELTA) + response.set_cookie(jwt_settings.JWT_AUTH_COOKIE, + self.token, + expires=expiration, + httponly=True) + return response def post(self, request, *args, **kwargs): self.request = request