From 41a21e24c805971672b76b39e98bae9601c1bd04 Mon Sep 17 00:00:00 2001 From: David Graham Date: Thu, 19 Sep 2024 20:49:46 -0400 Subject: [PATCH] remove django 3.2 support (which has reached end of life, and is no longer supported by django or django-allauth) and some minor additional fixes to use of datetime module --- dj_rest_auth/jwt_auth.py | 10 +++++----- dj_rest_auth/tests/requirements.pip | 6 ------ dj_rest_auth/tests/requirements.txt | 1 + setup.py | 2 +- tox.ini | 3 +-- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/dj_rest_auth/jwt_auth.py b/dj_rest_auth/jwt_auth.py index 95363eba..df7b0d40 100644 --- a/dj_rest_auth/jwt_auth.py +++ b/dj_rest_auth/jwt_auth.py @@ -1,4 +1,4 @@ -from datetime import timezone +from datetime import datetime from django.utils.translation import gettext_lazy as _ from rest_framework import status from rest_framework import exceptions, serializers @@ -12,7 +12,7 @@ def set_jwt_access_cookie(response, access_token): from rest_framework_simplejwt.settings import api_settings as jwt_settings cookie_name = api_settings.JWT_AUTH_COOKIE - access_token_expiration = (timezone.now() + jwt_settings.ACCESS_TOKEN_LIFETIME) + access_token_expiration = (datetime.utcnow() + jwt_settings.ACCESS_TOKEN_LIFETIME) cookie_secure = api_settings.JWT_AUTH_SECURE cookie_httponly = api_settings.JWT_AUTH_HTTPONLY cookie_samesite = api_settings.JWT_AUTH_SAMESITE @@ -32,7 +32,7 @@ def set_jwt_access_cookie(response, access_token): def set_jwt_refresh_cookie(response, refresh_token): from rest_framework_simplejwt.settings import api_settings as jwt_settings - refresh_token_expiration = (timezone.now() + jwt_settings.REFRESH_TOKEN_LIFETIME) + refresh_token_expiration = (datetime.utcnow() + jwt_settings.REFRESH_TOKEN_LIFETIME) refresh_cookie_name = api_settings.JWT_AUTH_REFRESH_COOKIE refresh_cookie_path = api_settings.JWT_AUTH_REFRESH_COOKIE_PATH cookie_secure = api_settings.JWT_AUTH_SECURE @@ -101,13 +101,13 @@ class RefreshViewWithCookieSupport(TokenRefreshView): def finalize_response(self, request, response, *args, **kwargs): if response.status_code == status.HTTP_200_OK and 'access' in response.data: set_jwt_access_cookie(response, response.data['access']) - response.data['access_expiration'] = (timezone.now() + jwt_settings.ACCESS_TOKEN_LIFETIME) + response.data['access_expiration'] = (datetime.utcnow() + jwt_settings.ACCESS_TOKEN_LIFETIME) if response.status_code == status.HTTP_200_OK and 'refresh' in response.data: set_jwt_refresh_cookie(response, response.data['refresh']) if api_settings.JWT_AUTH_HTTPONLY: del response.data['refresh'] else: - response.data['refresh_expiration'] = (timezone.now() + jwt_settings.REFRESH_TOKEN_LIFETIME) + response.data['refresh_expiration'] = (datetime.utcnow() + jwt_settings.REFRESH_TOKEN_LIFETIME) return super().finalize_response(request, response, *args, **kwargs) return RefreshViewWithCookieSupport diff --git a/dj_rest_auth/tests/requirements.pip b/dj_rest_auth/tests/requirements.pip index dc551394..e69de29b 100644 --- a/dj_rest_auth/tests/requirements.pip +++ b/dj_rest_auth/tests/requirements.pip @@ -1,6 +0,0 @@ -coveralls==1.11.1 -django-allauth==64.0.0 -djangorestframework-simplejwt>=5.3.1 -flake8==3.8.4 -responses==0.12.1 -unittest-xml-reporting==3.2.0 diff --git a/dj_rest_auth/tests/requirements.txt b/dj_rest_auth/tests/requirements.txt index c8b3bf8d..4734a174 100644 --- a/dj_rest_auth/tests/requirements.txt +++ b/dj_rest_auth/tests/requirements.txt @@ -4,3 +4,4 @@ djangorestframework-simplejwt>=5.3.1 flake8==3.8.4 responses==0.12.1 unittest-xml-reporting==3.0.4 +requests-oauthlib==2.0.0 diff --git a/setup.py b/setup.py index b8b9e55a..6c170970 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ keywords='django rest auth registration rest-framework django-registration api', zip_safe=False, install_requires=[ - 'Django>=3.2,<6.0', + 'Django>=4.2,<6.0', 'djangorestframework>=3.13.0', ], extras_require={ diff --git a/tox.ini b/tox.ini index afbacac6..3b21cb5a 100644 --- a/tox.ini +++ b/tox.ini @@ -24,8 +24,7 @@ commands = python ./runtests.py deps = -r dj_rest_auth/tests/requirements.txt - django3: Django>=3.2,<4.0 - django4: Django>=4.0,<5.0 + django4: Django>=4.2,<5.0 django5: Django>=5.0,<6.0 # Configuration for coverage and flake8 is being set in `./setup.cfg`