From 93de441b8bc3b3e870bec5ee373ec335b7f39850 Mon Sep 17 00:00:00 2001 From: mominur-helios Date: Wed, 7 Dec 2022 18:47:12 +0600 Subject: [PATCH] fix api endpoint issue --- api/authentication/serializers/login.py | 3 --- api/authentication/viewsets/social_login.py | 16 +++++----------- api/routers.py | 2 -- core/urls.py | 1 + 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/api/authentication/serializers/login.py b/api/authentication/serializers/login.py index f56b1cf..183ae31 100644 --- a/api/authentication/serializers/login.py +++ b/api/authentication/serializers/login.py @@ -64,6 +64,3 @@ def validate(self, data): } -class GithubSerializer(serializers.Serializer): - code = serializers.CharField(max_length=255) - diff --git a/api/authentication/viewsets/social_login.py b/api/authentication/viewsets/social_login.py index 98f31a0..05c2627 100644 --- a/api/authentication/viewsets/social_login.py +++ b/api/authentication/viewsets/social_login.py @@ -1,27 +1,21 @@ import requests import jwt - -from rest_framework import viewsets from rest_framework.response import Response from rest_framework.permissions import AllowAny from django.conf import settings from django.core.exceptions import ObjectDoesNotExist -from api.authentication.serializers.login import GithubSerializer, _generate_jwt_token +from api.authentication.serializers.login import _generate_jwt_token from api.user.models import User from api.authentication.models import ActiveSession +from rest_framework.views import APIView -class GithubSocialLogin(viewsets.ModelViewSet): - http_method_names = ["post"] +class GithubSocialLogin(APIView): permission_classes = (AllowAny,) - serializer_class = GithubSerializer - - def create(self, request, *args, **kwargs): - serializer = self.get_serializer(data=request.data) - serializer.is_valid(raise_exception=True) - code = serializer.data['code'] + def get(self, request): + code = self.request.GET.get('code') client_id = getattr(settings, 'GITHUB_CLIENT_ID') client_secret = getattr(settings, 'GITHUB_SECRET_KEY') root_url = 'https://github.com/login/oauth/access_token' diff --git a/api/routers.py b/api/routers.py index acfdc43..cc97a33 100644 --- a/api/routers.py +++ b/api/routers.py @@ -4,7 +4,6 @@ ActiveSessionViewSet, LogoutViewSet, ) -from api.authentication.viewsets.social_login import GithubSocialLogin from rest_framework import routers from api.user.viewsets import UserViewSet @@ -20,7 +19,6 @@ router.register(r"logout", LogoutViewSet, basename="logout") -router.register(r"github-login", GithubSocialLogin, basename="github-login") urlpatterns = [ *router.urls, diff --git a/core/urls.py b/core/urls.py index 0a0351e..163624c 100644 --- a/core/urls.py +++ b/core/urls.py @@ -5,4 +5,5 @@ urlpatterns = [ path('admin/', admin.site.urls), path("api/users/", include(("api.routers", "api"), namespace="api")), + path("api/sessions/oauth/github/", GithubSocialLogin.as_view(), name="github_login"), ]