diff --git a/drf_anonymous_login/authentication.py b/drf_anonymous_login/authentication.py index 3d28a75..4ac407e 100644 --- a/drf_anonymous_login/authentication.py +++ b/drf_anonymous_login/authentication.py @@ -7,13 +7,17 @@ AUTH_KEYWORD = "Token" AUTH_HEADER = "HTTP_X_AUTHORIZATION_ANONYMOUS" +AUTH_COOKIE = "anonymous_token" class AnonymousLoginAuthentication(authentication.BaseAuthentication): keyword = AUTH_KEYWORD def authenticate(self, request): - auth = request.META.get(AUTH_HEADER, "").split() + auth = ( + request.META.get(AUTH_HEADER, "").split() + or request.COOKIES.get(AUTH_COOKIE, "").split() + ) if not auth or auth[0].lower() != self.keyword.lower(): return None diff --git a/drf_anonymous_login/views.py b/drf_anonymous_login/views.py index 2f5a08b..bc3a36e 100644 --- a/drf_anonymous_login/views.py +++ b/drf_anonymous_login/views.py @@ -43,7 +43,9 @@ def create(self, request, *args, **kwargs): "headers": self.extract_request_headers(request), } ) - return Response({"token": user.token}, status=status.HTTP_201_CREATED) + response = Response({"token": user.token}, status=status.HTTP_201_CREATED) + response.set_cookie("anonymous_token", user.token) + return response class AnonymousLoginAuthenticationModelViewSet(viewsets.ModelViewSet):