From e70e598c57cb7e2741e992fad78a0ae62865b2d3 Mon Sep 17 00:00:00 2001 From: Ojakoo Date: Tue, 21 Jun 2022 21:35:59 +0300 Subject: [PATCH] #12 Changed djangorestframework-jwt to djangorestframework-simplejwt --- poetry.lock | 74 ++++++++++++++++++++++++++-------------------- pyproject.toml | 4 +-- sikweb/base.py | 4 +-- sikweb/settings.py | 5 ++-- webapp/urls.py | 11 ++++--- 5 files changed, 56 insertions(+), 42 deletions(-) diff --git a/poetry.lock b/poetry.lock index 05a0e1d..a1eeacd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -14,7 +14,7 @@ tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (> [[package]] name = "babel" -version = "2.10.1" +version = "2.10.3" description = "Internationalization utilities" category = "main" optional = false @@ -47,11 +47,11 @@ uvloop = ["uvloop (>=0.15.2)"] [[package]] name = "certifi" -version = "2022.5.18" +version = "2022.6.15" description = "Python package for providing Mozilla's CA Bundle." category = "main" optional = false -python-versions = ">=3.5" +python-versions = ">=3.6" [[package]] name = "charset-normalizer" @@ -77,7 +77,7 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""} [[package]] name = "colorama" -version = "0.4.4" +version = "0.4.5" description = "Cross-platform colored terminal text." category = "dev" optional = false @@ -303,15 +303,24 @@ django = ">=2.2" pytz = "*" [[package]] -name = "djangorestframework-jwt" -version = "1.11.0" -description = "JSON Web Token based authentication for Django REST framework" +name = "djangorestframework-simplejwt" +version = "5.2.0" +description = "A minimal JSON Web Token authentication plugin for Django REST Framework" category = "main" optional = false -python-versions = "*" +python-versions = ">=3.7" [package.dependencies] -PyJWT = ">=1.5.2,<2.0.0" +django = "*" +djangorestframework = "*" +pyjwt = ">=1.7.1,<3" + +[package.extras] +dev = ["pytest-watch", "wheel", "twine", "ipython", "cryptography", "pytest-cov", "pytest-django", "pytest-xdist", "pytest", "tox", "flake8", "pep8", "isort", "Sphinx (>=1.6.5,<2)", "sphinx-rtd-theme (>=0.1.9)", "python-jose (==3.3.0)"] +doc = ["Sphinx (>=1.6.5,<2)", "sphinx-rtd-theme (>=0.1.9)"] +lint = ["flake8", "pep8", "isort"] +python-jose = ["python-jose (==3.3.0)"] +test = ["cryptography", "pytest-cov", "pytest-django", "pytest-xdist", "pytest", "tox"] [[package]] name = "dparse" @@ -361,7 +370,7 @@ python-versions = ">=3.5" [[package]] name = "importlib-metadata" -version = "4.11.3" +version = "4.11.4" description = "Read metadata from Python packages" category = "main" optional = false @@ -482,7 +491,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" [[package]] name = "phonenumbers" -version = "8.12.48" +version = "8.12.50" description = "Python version of Google's common library for parsing, formatting, storing and validating international phone numbers." category = "main" optional = false @@ -568,16 +577,17 @@ pyexcel-io = ">=0.5.3" [[package]] name = "pyjwt" -version = "1.7.1" +version = "2.4.0" description = "JSON Web Token implementation in Python" category = "main" optional = false -python-versions = "*" +python-versions = ">=3.6" [package.extras] -crypto = ["cryptography (>=1.4)"] -flake8 = ["flake8", "flake8-import-order", "pep8-naming"] -test = ["pytest (>=4.0.1,<5.0.0)", "pytest-cov (>=2.6.0,<3.0.0)", "pytest-runner (>=4.2,<5.0.0)"] +crypto = ["cryptography (>=3.3.1)"] +dev = ["sphinx", "sphinx-rtd-theme", "zope.interface", "cryptography (>=3.3.1)", "pytest (>=6.0.0,<7.0.0)", "coverage[toml] (==5.0.4)", "mypy", "pre-commit"] +docs = ["sphinx", "sphinx-rtd-theme", "zope.interface"] +tests = ["pytest (>=6.0.0,<7.0.0)", "coverage[toml] (==5.0.4)"] [[package]] name = "pyparsing" @@ -839,7 +849,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "737b7278d4803532c7b5aee8fa95cabba24a20c70467d58fde5ab6d63c796ecf" +content-hash = "7bd8922d622b0f6a042c5508bb2789bb3fb69df3b3198ae0adca52ce12432887" [metadata.files] attrs = [ @@ -847,8 +857,8 @@ attrs = [ {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, ] babel = [ - {file = "Babel-2.10.1-py3-none-any.whl", hash = "sha256:3f349e85ad3154559ac4930c3918247d319f21910d5ce4b25d439ed8693b98d2"}, - {file = "Babel-2.10.1.tar.gz", hash = "sha256:98aeaca086133efb3e1e2aad0396987490c8425929ddbcfe0550184fdc54cd13"}, + {file = "Babel-2.10.3-py3-none-any.whl", hash = "sha256:ff56f4892c1c4bf0d814575ea23471c230d544203c7748e8c68f0089478d48eb"}, + {file = "Babel-2.10.3.tar.gz", hash = "sha256:7614553711ee97490f732126dc077f8d0ae084ebc6a96e23db1482afabdb2c51"}, ] black = [ {file = "black-22.3.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:2497f9c2386572e28921fa8bec7be3e51de6801f7459dffd6e62492531c47e09"}, @@ -876,8 +886,8 @@ black = [ {file = "black-22.3.0.tar.gz", hash = "sha256:35020b8886c022ced9282b51b5a875b6d1ab0c387b31a065b84db7c33085ca79"}, ] certifi = [ - {file = "certifi-2022.5.18-py3-none-any.whl", hash = "sha256:8d15a5a7fde18536a249c49e07e8e462b8fc13de21b3c80e8a68315dfa227c99"}, - {file = "certifi-2022.5.18.tar.gz", hash = "sha256:6ae10321df3e464305a46e997da41ea56c1d311fb9ff1dd4e04d6f14653ec63a"}, + {file = "certifi-2022.6.15-py3-none-any.whl", hash = "sha256:fe86415d55e84719d75f8b69414f6438ac3547d2078ab91b67e779ef69378412"}, + {file = "certifi-2022.6.15.tar.gz", hash = "sha256:84c85a9078b11105f04f3036a9482ae10e4621616db313fe045dd24743a0820d"}, ] charset-normalizer = [ {file = "charset-normalizer-2.0.12.tar.gz", hash = "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597"}, @@ -888,8 +898,8 @@ click = [ {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, ] colorama = [ - {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, - {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, + {file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"}, + {file = "colorama-0.4.5.tar.gz", hash = "sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4"}, ] coverage = [ {file = "coverage-5.5-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:b6d534e4b2ab35c9f93f46229363e17f63c53ad01330df9f2d6bd1187e5eaacf"}, @@ -1012,9 +1022,9 @@ djangorestframework = [ {file = "djangorestframework-3.13.1-py3-none-any.whl", hash = "sha256:24c4bf58ed7e85d1fe4ba250ab2da926d263cd57d64b03e8dcef0ac683f8b1aa"}, {file = "djangorestframework-3.13.1.tar.gz", hash = "sha256:0c33407ce23acc68eca2a6e46424b008c9c02eceb8cf18581921d0092bc1f2ee"}, ] -djangorestframework-jwt = [ - {file = "djangorestframework-jwt-1.11.0.tar.gz", hash = "sha256:5efe33032f3a4518a300dc51a51c92145ad95fb6f4b272e5aa24701db67936a7"}, - {file = "djangorestframework_jwt-1.11.0-py2.py3-none-any.whl", hash = "sha256:ab15dfbbe535eede8e2e53adaf52ef0cf018ee27dbfad10cbc4cbec2ab63d38c"}, +djangorestframework-simplejwt = [ + {file = "djangorestframework_simplejwt-5.2.0-py3-none-any.whl", hash = "sha256:bcc4cb74dcb637ca1e17eed35276bd618ab19491f8c53e65dee6271177c355e8"}, + {file = "djangorestframework_simplejwt-5.2.0.tar.gz", hash = "sha256:a60b09afb27d91ad1d7ac904cc632bd52cecead8f389f0fa1532ceb0fb757a74"}, ] dparse = [ {file = "dparse-0.5.1-py3-none-any.whl", hash = "sha256:e953a25e44ebb60a5c6efc2add4420c177f1d8404509da88da9729202f306994"}, @@ -1033,8 +1043,8 @@ idna = [ {file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"}, ] importlib-metadata = [ - {file = "importlib_metadata-4.11.3-py3-none-any.whl", hash = "sha256:1208431ca90a8cca1a6b8af391bb53c1a2db74e5d1cef6ddced95d4b2062edc6"}, - {file = "importlib_metadata-4.11.3.tar.gz", hash = "sha256:ea4c597ebf37142f827b8f39299579e31685c31d3a438b59f469406afd0f2539"}, + {file = "importlib_metadata-4.11.4-py3-none-any.whl", hash = "sha256:c58c8eb8a762858f49e18436ff552e83914778e50e9d2f1660535ffb364552ec"}, + {file = "importlib_metadata-4.11.4.tar.gz", hash = "sha256:5d26852efe48c0a32b0509ffbc583fda1a2266545a78d104a6f4aff3db17d700"}, ] jdcal = [ {file = "jdcal-1.4.1-py2.py3-none-any.whl", hash = "sha256:1abf1305fce18b4e8aa248cf8fe0c56ce2032392bc64bbd61b5dff2a19ec8bba"}, @@ -1076,8 +1086,8 @@ pathspec = [ {file = "pathspec-0.9.0.tar.gz", hash = "sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"}, ] phonenumbers = [ - {file = "phonenumbers-8.12.48-py2.py3-none-any.whl", hash = "sha256:429273b98966475d0c18ee293096eaf81c6b5727d0d55c7ba5ce9c60ec8c59ef"}, - {file = "phonenumbers-8.12.48.tar.gz", hash = "sha256:af0681fbfe9fa0721376ad9b729e772e5d20bf2cf50d9dd8ca2f0bdd78e9f0ce"}, + {file = "phonenumbers-8.12.50-py2.py3-none-any.whl", hash = "sha256:56713403b4160b59ea1fef4e842ddeb70931055146d794d371b60cd4b5f05fb8"}, + {file = "phonenumbers-8.12.50.tar.gz", hash = "sha256:f00d67f20875804f4fade4803a9438294029982ac929c6ba303e1f0290cf5d45"}, ] pillow = [ {file = "Pillow-9.1.1-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:42dfefbef90eb67c10c45a73a9bc1599d4dac920f7dfcbf4ec6b80cb620757fe"}, @@ -1173,8 +1183,8 @@ pyexcel-xlsx = [ {file = "pyexcel_xlsx-0.5.8-py2.py3-none-any.whl", hash = "sha256:9bae2820c5767440d8a387695e0f8e8f73c97bcde0a5680c200ae82a2f6d5cc6"}, ] pyjwt = [ - {file = "PyJWT-1.7.1-py2.py3-none-any.whl", hash = "sha256:5c6eca3c2940464d106b99ba83b00c6add741c9becaec087fb7ccdefea71350e"}, - {file = "PyJWT-1.7.1.tar.gz", hash = "sha256:8d59a976fb773f3e6a39c85636357c4f0e242707394cadadd9814f5cbaa20e96"}, + {file = "PyJWT-2.4.0-py3-none-any.whl", hash = "sha256:72d1d253f32dbd4f5c88eaf1fdc62f3a19f676ccbadb9dbc5d07e951b2b26daf"}, + {file = "PyJWT-2.4.0.tar.gz", hash = "sha256:d42908208c699b3b973cbeb01a969ba6a96c821eefb1c5bfe4c390c01d67abba"}, ] pyparsing = [ {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, diff --git a/pyproject.toml b/pyproject.toml index 5367382..7fc3cd6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,10 +8,9 @@ authors = ["Aarni Halinen aarni.halinen@sahkoinsinoorikilta.fi"] python = "^3.9" decorator = "^4.0.9" Django = "^2.2.19" -requests = "^2.11.1" +requests = "2.27.1" django-cors-headers = "^3.7.0" djangorestframework = "^3.12.4" -djangorestframework-jwt = "^1.11.0" django-nose = "^1.4.5" psycopg2-binary = "2.8.6" django-bootstrap3 = "^11.1.0" @@ -38,6 +37,7 @@ sendgrid = "^6.7.0" sentry-sdk = "^1.4.3" django-polymorphic = "^3.1.0" python-dotenv = "^0.20.0" +djangorestframework-simplejwt = "^5.2.0" [tool.poetry.dev-dependencies] coverage = "^5.5" diff --git a/sikweb/base.py b/sikweb/base.py index d7ca7f6..07c1e0a 100644 --- a/sikweb/base.py +++ b/sikweb/base.py @@ -87,7 +87,7 @@ INSTALLED_APPS = [ "kaehmy", "ohlhafv", "rest_framework", - "rest_framework_jwt", + "rest_framework_simplejwt", "django_nose", "bootstrap3", "django_tables2", @@ -178,7 +178,7 @@ REST_FRAMEWORK = { "rest_framework.permissions.IsAdminUser", ), "DEFAULT_AUTHENTICATION_CLASSES": ( - "rest_framework_jwt.authentication.JSONWebTokenAuthentication", + "rest_framework_simplejwt.authentication.JWTAuthentication", ), # 'DEFAULT_THROTTLE_CLASSES': ( # 'members.throttles.BurstRateThrottle', diff --git a/sikweb/settings.py b/sikweb/settings.py index e81d4de..d85f392 100644 --- a/sikweb/settings.py +++ b/sikweb/settings.py @@ -14,6 +14,7 @@ from dotenv import load_dotenv import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from sikweb.base import * +from datetime import timedelta load_dotenv() # loads the configs from .env @@ -61,7 +62,7 @@ DEFAULT_EMAIL_FROM = "SIK" DEFAULT_EMAIL_FROM_ADDR = "noreply@sahkoinsinoorikilta.fi" ENABLE_AUTOMATIC_EMAILS = True -# Database settings +# Database settingsfrom datetime import timedelta # Only uncomment if default settings in base.py are not ok DB_OPTIONS = {"sslmode": "require"} if os.getenv("DB_SSL", False) == "True" else {} @@ -76,4 +77,4 @@ DATABASES = { "PORT": os.getenv("DB_PORT", 5432), "OPTIONS": DB_OPTIONS, } -} +} \ No newline at end of file diff --git a/webapp/urls.py b/webapp/urls.py index adb7af4..c5238f3 100644 --- a/webapp/urls.py +++ b/webapp/urls.py @@ -1,15 +1,15 @@ """Webapp urls.""" from django.conf.urls import url, include +from django.urls import path from rest_framework import routers -from rest_framework_jwt.views import obtain_jwt_token, verify_jwt_token +from rest_framework_simplejwt.views import (TokenObtainPairView, TokenRefreshView) from webapp.views import * class APIRouter(routers.DefaultRouter): APIRootView = RootView - router = APIRouter() router.register(r"events", EventViewSet) router.register(r"signupForm", SignupFormViewSet) @@ -21,7 +21,10 @@ router.register(r"jobads", JobAdViewSet) urlpatterns = [ url(r"^api/", include(router.urls)), - url(r"^api/api-token-auth/", obtain_jwt_token), - url(r"^api/api-token-verify/", verify_jwt_token), + path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), + path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), url(r"^jwt_nginx", nginx_jwt_resp), ] + +# url(r"^api/api-token-auth/", obtain_jwt_token), +# url(r"^api/api-token-verify/", verify_jwt_token), \ No newline at end of file