Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Sep 24, 2024
1 parent 3b6f21f commit c1a0b13
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 269 deletions.
17 changes: 0 additions & 17 deletions .vscode/launch.json

This file was deleted.

27 changes: 0 additions & 27 deletions backoffice/backoffice/users/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
57 changes: 0 additions & 57 deletions backoffice/backoffice/users/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
13 changes: 0 additions & 13 deletions backoffice/backoffice/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
7 changes: 2 additions & 5 deletions backoffice/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"allauth",
"allauth.account",
"allauth.socialaccount",
#"allauth.headless",
"allauth.headless",
"allauth.socialaccount.providers.orcid",
"django_celery_beat",
"rest_framework",
Expand All @@ -107,8 +107,6 @@
"django_elasticsearch_dsl_drf",
"rest_framework_simplejwt",
"django_json_widget",
"dj_rest_auth",
"dj_rest_auth.registration",
]

REST_AUTH = {
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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",
Expand Down
7 changes: 1 addition & 6 deletions backoffice/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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")),
]


Expand Down
Loading

0 comments on commit c1a0b13

Please sign in to comment.