mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-12-02 13:53:43 +03:00
changed for use w/ cookies
This commit is contained in:
parent
6dd2aea624
commit
12e79aa33e
|
@ -18,7 +18,6 @@ def default_create_token(token_model, user, serializer):
|
||||||
def jwt_encode(user):
|
def jwt_encode(user):
|
||||||
try:
|
try:
|
||||||
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
||||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError("rest-framework-simplejwt needs to be installed")
|
raise ImportError("rest-framework-simplejwt needs to be installed")
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,15 @@ class LoginView(GenericAPIView):
|
||||||
context={'request': self.request})
|
context={'request': self.request})
|
||||||
|
|
||||||
response = 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_simplejwt.settings import api_settings as jwt_settings
|
||||||
|
#if jwt_settings.JWT_AUTH_COOKIE #this needs to be added to simplejwt
|
||||||
|
from datetime import datetime
|
||||||
|
expiration = (datetime.utcnow() + jwt_settings.ACCESS_TOKEN_LIFETIME)
|
||||||
|
response.set_cookie('somestring', #replace with jwt_settings.JWT_AUTH_COOKIE
|
||||||
|
self.access_token,
|
||||||
|
expires=expiration,
|
||||||
|
httponly=True)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
@ -125,6 +134,10 @@ class LogoutView(APIView):
|
||||||
|
|
||||||
response = Response({"detail": _("Successfully logged out.")},
|
response = Response({"detail": _("Successfully logged out.")},
|
||||||
status=status.HTTP_200_OK)
|
status=status.HTTP_200_OK)
|
||||||
|
if getattr(settings, 'REST_USE_JWT', False):
|
||||||
|
from rest_framework_simplejwt.settings import api_settings as jwt_settings
|
||||||
|
#if jwt_settings.JWT_AUTH_COOKIE #this needs to be added to simplejwt
|
||||||
|
response.delete_cookie('somestring') #replace with jwt_settings.JWT_AUTH_COOKIE
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user