From c1a0b13800d424e846d51089793e6f0f39157193 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Tue, 24 Sep 2024 11:13:54 +0200 Subject: [PATCH] asd --- .vscode/launch.json | 17 --- backoffice/backoffice/users/adapters.py | 27 ---- backoffice/backoffice/users/api/views.py | 57 --------- backoffice/backoffice/users/views.py | 13 -- backoffice/config/settings/base.py | 7 +- backoffice/config/urls.py | 7 +- backoffice/poetry.lock | 152 ++--------------------- backoffice/pyproject.toml | 2 +- 8 files changed, 13 insertions(+), 269 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 328a0ba5..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Run Django Debug Pt", - "type": "debugpy", - "request": "attach", - "pathMappings": [ - { - "localRoot": "${workspaceFolder}/backoffice", - "remoteRoot": "/app/backoffice" - } - ], - "connect": {"host": "127.0.0.1","port": 8000}, - } - ] - } diff --git a/backoffice/backoffice/users/adapters.py b/backoffice/backoffice/users/adapters.py index db81a4ac..9dda142b 100644 --- a/backoffice/backoffice/users/adapters.py +++ b/backoffice/backoffice/users/adapters.py @@ -23,33 +23,7 @@ def is_open_for_signup( self, request: HttpRequest, sociallogin: SocialLogin ) -> bool: return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True) - - import urllib.parse - from django.http import HttpResponseRedirect - def pre_social_login(self, request, sociallogin): - print("PRE SOCIAL SIGNUP") - print(str(request.user)) - print(str(request)) - print(request.META) - print(sociallogin.serialize()) - # import urllib - # email = sociallogin.account.extra_data.get('email') - # # If email is missing, serialize the social login data and pass it to Flask - # if not email: - # # Serialize the social login data - # sociallogin_data = sociallogin.serialize() - # session_token = request.session.session_key # Optional: Store session key for further authentication - - # # URL encode the social login data to send it securely to Flask - # flask_redirect_url = 'http://localhost:5000/fill-email' - # query_params = { - # 'sociallogin': urllib.parse.quote(sociallogin_data), - # 'session_token': session_token - # } - - # url_with_params = f"{flask_redirect_url}?{urllib.parse.urlencode(query_params)}" - # return HttpResponseRedirect(url_with_params) def populate_user( @@ -63,7 +37,6 @@ def populate_user( See: https://django-allauth.readthedocs.io/en/latest/advanced.html?#creating-and-populating-user-instances """ - print("adapter is adapting") user = sociallogin.user if name := data.get("name"): user.name = name diff --git a/backoffice/backoffice/users/api/views.py b/backoffice/backoffice/users/api/views.py index 66bf5cda..0ecd2ac9 100644 --- a/backoffice/backoffice/users/api/views.py +++ b/backoffice/backoffice/users/api/views.py @@ -4,7 +4,6 @@ from allauth.socialaccount.providers.oauth2.client import OAuth2Client from allauth.socialaccount.providers.orcid.views import OrcidOAuth2Adapter -from dj_rest_auth.registration.views import SocialConnectView, SocialLoginView from django.contrib.auth import get_user_model from rest_framework import status from rest_framework.decorators import action @@ -30,59 +29,3 @@ def get_queryset(self, *args, **kwargs): def me(self, request): serializer = UserSerializer(request.user, context={"request": request}) return Response(status=status.HTTP_200_OK, data=serializer.data) - - -from django.conf import settings -class OrcidLogin(SocialLoginView): - adapter_class = OrcidOAuth2Adapter - client_class = OAuth2Client - callback_url = "http://localhost:8000/api/oauth/authorized/orcid/" - - def process_login(self): - #import ipdb; ipdb.set_trace() - return super().process_login() - - - - - -class OrcidConnect(SocialConnectView): - adapter_class = OrcidOAuth2Adapter - -from django.views.decorators.csrf import csrf_exempt -from rest_framework.permissions import AllowAny - -from django.shortcuts import redirect -class OrcidLoginCallback(APIView): - permission_classes = [AllowAny] # Allow access to everyone - - @csrf_exempt # Disable CSRF token check for testing purposes (optional) - def get(self, request, *args, **kwargs): - """ - If you are building a fullstack application (eq. with React app next to Django) - you can place this endpoint in your frontend application to receive - the JWT tokens there - and store them in the state - """ - - params = request.GET.urlencode() - - - - # Redirect to the target view with all parameters - return redirect(f"http://localhost:5000/callback?{params}") - - code = request.GET.get("code") - - if code is None: - return Response(status=status.HTTP_400_BAD_REQUEST) - - # Remember to replace the localhost:8000 with the actual domain name before deployment - token_endpoint_url = urljoin("http://localhost:8000", reverse("orcid_login2")) - response = requests.post(url=token_endpoint_url, data={"code": code}) - - data = response.json() - if data["user"]["email"]=="": - - redirect - - return Response(response.json(), status=status.HTTP_200_OK) diff --git a/backoffice/backoffice/users/views.py b/backoffice/backoffice/users/views.py index 198e54d5..2c043c89 100644 --- a/backoffice/backoffice/users/views.py +++ b/backoffice/backoffice/users/views.py @@ -41,19 +41,6 @@ class UserRedirectView(LoginRequiredMixin, RedirectView): def get_redirect_url(self): return reverse("users:detail", kwargs={"pk": self.request.user.pk}) - -import requests - -from django.http import HttpResponse, JsonResponse -from django.shortcuts import redirect -def orcid_callback(request): - - #url = request.build_absolute_uri('/accounts/orcid/login/callback/')) - #params = request.GET.urlencode() - #return redirect(f"/accounts/orcid/login/callback/?{params}") - return HttpResponse("Send a POST request to see the body.", content_type="text/plain") - - def success(request): import ipdb;ipdb.set_trace() return JsonResponse(data={"wow":request.user.email}) diff --git a/backoffice/config/settings/base.py b/backoffice/config/settings/base.py index 0886ac35..a4879d49 100644 --- a/backoffice/config/settings/base.py +++ b/backoffice/config/settings/base.py @@ -95,7 +95,7 @@ "allauth", "allauth.account", "allauth.socialaccount", - #"allauth.headless", + "allauth.headless", "allauth.socialaccount.providers.orcid", "django_celery_beat", "rest_framework", @@ -107,8 +107,6 @@ "django_elasticsearch_dsl_drf", "rest_framework_simplejwt", "django_json_widget", - "dj_rest_auth", - "dj_rest_auth.registration", ] REST_AUTH = { @@ -138,7 +136,7 @@ # https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model AUTH_USER_MODEL = "users.User" # https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url -LOGIN_REDIRECT_URL = "/accounts/login/success/" +LOGIN_REDIRECT_URL = "http://127.0.0.1:5000/success" # https://docs.djangoproject.com/en/dev/ref/settings/#login-url LOGIN_URL = "account_login" @@ -360,7 +358,6 @@ "rest_framework.authentication.SessionAuthentication", "rest_framework.authentication.TokenAuthentication", "rest_framework_simplejwt.authentication.JWTAuthentication", - "dj_rest_auth.jwt_auth.JWTCookieAuthentication", ), "DEFAULT_PERMISSION_CLASSES": ( "backoffice.management.permissions.IsAdminOrCuratorUser", diff --git a/backoffice/config/urls.py b/backoffice/config/urls.py index 1d507af3..dd60de65 100644 --- a/backoffice/config/urls.py +++ b/backoffice/config/urls.py @@ -10,7 +10,6 @@ from rest_framework.authtoken.views import obtain_auth_token from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView -from backoffice.users.api.views import OrcidConnect, OrcidLogin, OrcidLoginCallback from backoffice.users.views import success urlpatterns = [ @@ -47,11 +46,7 @@ ), path("api/token/", TokenObtainPairView.as_view(), name="token_obtain_pair"), path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"), - #path("_allauth/", include("allauth.headless.urls")), - path("dj-rest-auth/", include("dj_rest_auth.urls")), - path("dj-rest-auth/registration/", include("dj_rest_auth.registration.urls")), - path("dj-rest-auth/orcid/", OrcidLogin.as_view(), name="orcid_login2"), - path("dj-rest-auth/orcid/connect/", OrcidConnect.as_view(), name="orcid_connect"), + path("_allauth/", include("allauth.headless.urls")), ] diff --git a/backoffice/poetry.lock b/backoffice/poetry.lock index d35bc54b..cc13c032 100644 --- a/backoffice/poetry.lock +++ b/backoffice/poetry.lock @@ -702,55 +702,6 @@ files = [ [package.extras] dev = ["polib"] -[[package]] -name = "cryptography" -version = "43.0.1" -description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers." -optional = false -python-versions = ">=3.7" -files = [ - {file = "cryptography-43.0.1-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:8385d98f6a3bf8bb2d65a73e17ed87a3ba84f6991c155691c51112075f9ffc5d"}, - {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:27e613d7077ac613e399270253259d9d53872aaf657471473ebfc9a52935c062"}, - {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:68aaecc4178e90719e95298515979814bda0cbada1256a4485414860bd7ab962"}, - {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:de41fd81a41e53267cb020bb3a7212861da53a7d39f863585d13ea11049cf277"}, - {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f98bf604c82c416bc829e490c700ca1553eafdf2912a91e23a79d97d9801372a"}, - {file = "cryptography-43.0.1-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:61ec41068b7b74268fa86e3e9e12b9f0c21fcf65434571dbb13d954bceb08042"}, - {file = "cryptography-43.0.1-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:014f58110f53237ace6a408b5beb6c427b64e084eb451ef25a28308270086494"}, - {file = "cryptography-43.0.1-cp37-abi3-win32.whl", hash = "sha256:2bd51274dcd59f09dd952afb696bf9c61a7a49dfc764c04dd33ef7a6b502a1e2"}, - {file = "cryptography-43.0.1-cp37-abi3-win_amd64.whl", hash = "sha256:666ae11966643886c2987b3b721899d250855718d6d9ce41b521252a17985f4d"}, - {file = "cryptography-43.0.1-cp39-abi3-macosx_10_9_universal2.whl", hash = "sha256:ac119bb76b9faa00f48128b7f5679e1d8d437365c5d26f1c2c3f0da4ce1b553d"}, - {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1bbcce1a551e262dfbafb6e6252f1ae36a248e615ca44ba302df077a846a8806"}, - {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:58d4e9129985185a06d849aa6df265bdd5a74ca6e1b736a77959b498e0505b85"}, - {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:d03a475165f3134f773d1388aeb19c2d25ba88b6a9733c5c590b9ff7bbfa2e0c"}, - {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:511f4273808ab590912a93ddb4e3914dfd8a388fed883361b02dea3791f292e1"}, - {file = "cryptography-43.0.1-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:80eda8b3e173f0f247f711eef62be51b599b5d425c429b5d4ca6a05e9e856baa"}, - {file = "cryptography-43.0.1-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:38926c50cff6f533f8a2dae3d7f19541432610d114a70808f0926d5aaa7121e4"}, - {file = "cryptography-43.0.1-cp39-abi3-win32.whl", hash = "sha256:a575913fb06e05e6b4b814d7f7468c2c660e8bb16d8d5a1faf9b33ccc569dd47"}, - {file = "cryptography-43.0.1-cp39-abi3-win_amd64.whl", hash = "sha256:d75601ad10b059ec832e78823b348bfa1a59f6b8d545db3a24fd44362a1564cb"}, - {file = "cryptography-43.0.1-pp310-pypy310_pp73-macosx_10_9_x86_64.whl", hash = "sha256:ea25acb556320250756e53f9e20a4177515f012c9eaea17eb7587a8c4d8ae034"}, - {file = "cryptography-43.0.1-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:c1332724be35d23a854994ff0b66530119500b6053d0bd3363265f7e5e77288d"}, - {file = "cryptography-43.0.1-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:fba1007b3ef89946dbbb515aeeb41e30203b004f0b4b00e5e16078b518563289"}, - {file = "cryptography-43.0.1-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:5b43d1ea6b378b54a1dc99dd8a2b5be47658fe9a7ce0a58ff0b55f4b43ef2b84"}, - {file = "cryptography-43.0.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:88cce104c36870d70c49c7c8fd22885875d950d9ee6ab54df2745f83ba0dc365"}, - {file = "cryptography-43.0.1-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:9d3cdb25fa98afdd3d0892d132b8d7139e2c087da1712041f6b762e4f807cc96"}, - {file = "cryptography-43.0.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:e710bf40870f4db63c3d7d929aa9e09e4e7ee219e703f949ec4073b4294f6172"}, - {file = "cryptography-43.0.1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:7c05650fe8023c5ed0d46793d4b7d7e6cd9c04e68eabe5b0aeea836e37bdcec2"}, - {file = "cryptography-43.0.1.tar.gz", hash = "sha256:203e92a75716d8cfb491dc47c79e17d0d9207ccffcbcb35f598fbe463ae3444d"}, -] - -[package.dependencies] -cffi = {version = ">=1.12", markers = "platform_python_implementation != \"PyPy\""} - -[package.extras] -docs = ["sphinx (>=5.3.0)", "sphinx-rtd-theme (>=1.1.1)"] -docstest = ["pyenchant (>=1.6.11)", "readme-renderer", "sphinxcontrib-spelling (>=4.0.1)"] -nox = ["nox"] -pep8test = ["check-sdist", "click", "mypy", "ruff"] -sdist = ["build"] -ssh = ["bcrypt (>=3.1.5)"] -test = ["certifi", "cryptography-vectors (==43.0.1)", "pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-xdist"] -test-randomorder = ["pytest-randomly"] - [[package]] name = "cssbeautifier" version = "1.14.9" @@ -792,17 +743,6 @@ files = [ {file = "decorator-5.1.1.tar.gz", hash = "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330"}, ] -[[package]] -name = "defusedxml" -version = "0.7.1" -description = "XML bomb protection for Python stdlib modules" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" -files = [ - {file = "defusedxml-0.7.1-py2.py3-none-any.whl", hash = "sha256:a352e7e428770286cc899e2542b6cdaedb2b4953ff269a210103ec58f6198a61"}, - {file = "defusedxml-0.7.1.tar.gz", hash = "sha256:1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69"}, -] - [[package]] name = "dill" version = "0.3.7" @@ -843,24 +783,6 @@ files = [ Django = ">=3.2" typing-extensions = ">=3.10.0.0" -[[package]] -name = "dj-rest-auth" -version = "6.0.0" -description = "Authentication and Registration in Django Rest Framework" -optional = false -python-versions = ">=3.8" -files = [ - {file = "dj-rest-auth-6.0.0.tar.gz", hash = "sha256:760b45f3a07cd6182e6a20fe07d0c55230c5f950167df724d7914d0dd8c50133"}, -] - -[package.dependencies] -Django = ">=3.2,<6.0" -django-allauth = {version = ">=0.56.0,<0.62.0", optional = true, markers = "extra == \"with_social\""} -djangorestframework = ">=3.13.0" - -[package.extras] -with-social = ["django-allauth (>=0.56.0,<0.62.0)"] - [[package]] name = "django" version = "4.2.6" @@ -883,24 +805,23 @@ bcrypt = ["bcrypt"] [[package]] name = "django-allauth" -version = "0.61.1" +version = "65.0.1" description = "Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "django-allauth-0.61.1.tar.gz", hash = "sha256:5b4ae515ea74f54f0041210692eee10c309ad15ddbbd03d3620693c75e3f7945"}, + {file = "django_allauth-65.0.1.tar.gz", hash = "sha256:1f8281e2dc17d3b977bcd95b99538f128c5cd2fb2551346a7f8ad31aa76f17cc"}, ] [package.dependencies] -Django = ">=3.2" -pyjwt = {version = ">=1.7", extras = ["crypto"]} -python3-openid = ">=3.0.8" -requests = ">=2.0.0" -requests-oauthlib = ">=0.3.0" +Django = ">=4.2" [package.extras] -mfa = ["qrcode (>=7.0.0)"] +mfa = ["fido2 (>=1.1.2)", "qrcode (>=7.0.0)"] +openid = ["python3-openid (>=3.0.8)"] saml = ["python3-saml (>=1.15.0,<2.0.0)"] +socialaccount = ["pyjwt[crypto] (>=1.7)", "requests (>=2.0.0)", "requests-oauthlib (>=0.3.0)"] +steam = ["python3-openid (>=3.0.8)"] [[package]] name = "django-anymail" @@ -2244,22 +2165,6 @@ files = [ [package.dependencies] setuptools = "*" -[[package]] -name = "oauthlib" -version = "3.2.2" -description = "A generic, spec-compliant, thorough implementation of the OAuth request-signing logic" -optional = false -python-versions = ">=3.6" -files = [ - {file = "oauthlib-3.2.2-py3-none-any.whl", hash = "sha256:8139f29aac13e25d502680e9e19963e83f16838d48a0d71c287fe40e7067fbca"}, - {file = "oauthlib-3.2.2.tar.gz", hash = "sha256:9859c40929662bec5d64f34d01c99e093149682a3f38915dc0655d5a633dd918"}, -] - -[package.extras] -rsa = ["cryptography (>=3.0.0)"] -signals = ["blinker (>=1.4.0)"] -signedtoken = ["cryptography (>=3.0.0)", "pyjwt (>=2.0.0,<3)"] - [[package]] name = "opensearch" version = "0.9.2" @@ -2650,9 +2555,6 @@ files = [ {file = "PyJWT-2.8.0.tar.gz", hash = "sha256:57e28d156e3d5c10088e0c68abb90bfac3df82b40a71bd0daa20c65ccd5c23de"}, ] -[package.dependencies] -cryptography = {version = ">=3.4.0", optional = true, markers = "extra == \"crypto\""} - [package.extras] crypto = ["cryptography (>=3.4.0)"] dev = ["coverage[toml] (==5.0.4)", "cryptography (>=3.4.0)", "pre-commit", "pytest (>=6.0.0,<7.0.0)", "sphinx (>=4.5.0,<5.0.0)", "sphinx-rtd-theme", "zope.interface"] @@ -2866,24 +2768,6 @@ text-unidecode = ">=1.3" [package.extras] unidecode = ["Unidecode (>=1.1.1)"] -[[package]] -name = "python3-openid" -version = "3.2.0" -description = "OpenID support for modern servers and consumers." -optional = false -python-versions = "*" -files = [ - {file = "python3-openid-3.2.0.tar.gz", hash = "sha256:33fbf6928f401e0b790151ed2b5290b02545e8775f982485205a066f874aaeaf"}, - {file = "python3_openid-3.2.0-py3-none-any.whl", hash = "sha256:6626f771e0417486701e0b4daff762e7212e820ca5b29fcc0d05f6f8736dfa6b"}, -] - -[package.dependencies] -defusedxml = "*" - -[package.extras] -mysql = ["mysql-connector-python"] -postgresql = ["psycopg2"] - [[package]] name = "pytz" version = "2023.3.post1" @@ -3106,24 +2990,6 @@ urllib3 = ">=1.21.1,<3" socks = ["PySocks (>=1.5.6,!=1.5.7)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] -[[package]] -name = "requests-oauthlib" -version = "2.0.0" -description = "OAuthlib authentication support for Requests." -optional = false -python-versions = ">=3.4" -files = [ - {file = "requests-oauthlib-2.0.0.tar.gz", hash = "sha256:b3dffaebd884d8cd778494369603a9e7b58d29111bf6b41bdc2dcd87203af4e9"}, - {file = "requests_oauthlib-2.0.0-py2.py3-none-any.whl", hash = "sha256:7dd8a5c40426b779b0868c404bdef9768deccf22749cde15852df527e6269b36"}, -] - -[package.dependencies] -oauthlib = ">=3.0.0" -requests = ">=2.0.0" - -[package.extras] -rsa = ["oauthlib[signedtoken] (>=3.0.0)"] - [[package]] name = "rpds-py" version = "0.10.4" @@ -4054,4 +3920,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "~3.11" -content-hash = "22c2a16a5c1b30d3ee38a4c92e2b7b079fe0d49e36784309a28dcf0c091703ff" +content-hash = "9136878f2aef5ac03a36f53cc140d3b18dfdaaf382b85d13ab37aa78d23fe018" diff --git a/backoffice/pyproject.toml b/backoffice/pyproject.toml index 5e206c8a..4ca1d901 100644 --- a/backoffice/pyproject.toml +++ b/backoffice/pyproject.toml @@ -149,7 +149,7 @@ opensearch-py = "2.6.0" djangorestframework-simplejwt = "^5.3.1" django-json-widget = "^2.0.1" sentry-sdk = "1.19.1" -dj-rest-auth = {version = "6.0.0", extras = ["with_social"]} +django-allauth = {version = "65.0.1", extras = ["headless"]} [tool.poetry.dev-dependencies] factory-boy = "3.3.0"