diff --git a/config/settings/base.py b/config/settings/base.py index dd82c1b5..f9d3048e 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -101,6 +101,7 @@ "django_prometheus", "django_opensearch_dsl", "django_elasticsearch_dsl_drf", + "rest_framework_simplejwt", ] LOCAL_APPS = ["backoffice.users", "backoffice.workflows", "backoffice.management"] @@ -341,6 +342,7 @@ "DEFAULT_AUTHENTICATION_CLASSES": ( "rest_framework.authentication.SessionAuthentication", "rest_framework.authentication.TokenAuthentication", + 'rest_framework_simplejwt.authentication.JWTAuthentication', ), "DEFAULT_PERMISSION_CLASSES": ("backoffice.management.permissions.IsAdminOrCuratorUser",), "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", diff --git a/config/urls.py b/config/urls.py index 381dc728..041ebdf1 100644 --- a/config/urls.py +++ b/config/urls.py @@ -7,6 +7,10 @@ from django.views.generic import TemplateView from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView from rest_framework.authtoken.views import obtain_auth_token +from rest_framework_simplejwt.views import ( + TokenObtainPairView, + TokenRefreshView, +) from backoffice.workflows.admin import workflow_admin_site @@ -38,6 +42,8 @@ SpectacularSwaggerView.as_view(url_name="api-schema"), name="api-docs", ), + path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), + path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), ] if settings.DEBUG: diff --git a/poetry.lock b/poetry.lock index f134935e..97316303 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "amqp" @@ -1200,6 +1200,30 @@ files = [ django = ">=3.0" pytz = "*" +[[package]] +name = "djangorestframework-simplejwt" +version = "5.3.1" +description = "A minimal JSON Web Token authentication plugin for Django REST Framework" +optional = false +python-versions = ">=3.8" +files = [ + {file = "djangorestframework_simplejwt-5.3.1-py3-none-any.whl", hash = "sha256:381bc966aa46913905629d472cd72ad45faa265509764e20ffd440164c88d220"}, + {file = "djangorestframework_simplejwt-5.3.1.tar.gz", hash = "sha256:6c4bd37537440bc439564ebf7d6085e74c5411485197073f508ebdfa34bc9fae"}, +] + +[package.dependencies] +django = ">=3.2" +djangorestframework = ">=3.12" +pyjwt = ">=1.7.1,<3" + +[package.extras] +crypto = ["cryptography (>=3.3.1)"] +dev = ["Sphinx (>=1.6.5,<2)", "cryptography", "flake8", "freezegun", "ipython", "isort", "pep8", "pytest", "pytest-cov", "pytest-django", "pytest-watch", "pytest-xdist", "python-jose (==3.3.0)", "sphinx_rtd_theme (>=0.1.9)", "tox", "twine", "wheel"] +doc = ["Sphinx (>=1.6.5,<2)", "sphinx_rtd_theme (>=0.1.9)"] +lint = ["flake8", "isort", "pep8"] +python-jose = ["python-jose (==3.3.0)"] +test = ["cryptography", "freezegun", "pytest", "pytest-cov", "pytest-django", "pytest-xdist", "tox"] + [[package]] name = "djangorestframework-stubs" version = "3.14.3" @@ -2736,7 +2760,6 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -3752,4 +3775,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "~3.11" -content-hash = "44e48fe5ddc7a842a3dce33103b246cf9a2b30020d68d10c015731e9eb39578d" +content-hash = "513c738f634b5100805f018953c91c5a6c26b2df4527f792c7368509e1c0e36d" diff --git a/pyproject.toml b/pyproject.toml index d255313c..44f4a80d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -148,6 +148,7 @@ elasticsearch = "6.8.2" django-elasticsearch-dsl-drf = {git = "https://github.com/cern-sis/django-elasticsearch-dsl-drf.git", rev = "opensearch"} opensearch-dsl = "^2.1.0" opensearch-py = "2.6.0" +djangorestframework-simplejwt = "^5.3.1" [tool.poetry.dev-dependencies] factory-boy = "3.3.0"