Skip to content

Commit 93de441

Browse files
author
mominur-helios
committed
fix api endpoint issue
1 parent 990cc00 commit 93de441

File tree

4 files changed

+6
-16
lines changed

4 files changed

+6
-16
lines changed

api/authentication/serializers/login.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,3 @@ def validate(self, data):
6464
}
6565

6666

67-
class GithubSerializer(serializers.Serializer):
68-
code = serializers.CharField(max_length=255)
69-

api/authentication/viewsets/social_login.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
import requests
22
import jwt
3-
4-
from rest_framework import viewsets
53
from rest_framework.response import Response
64
from rest_framework.permissions import AllowAny
75
from django.conf import settings
86
from django.core.exceptions import ObjectDoesNotExist
97

10-
from api.authentication.serializers.login import GithubSerializer, _generate_jwt_token
8+
from api.authentication.serializers.login import _generate_jwt_token
119
from api.user.models import User
1210
from api.authentication.models import ActiveSession
1311

12+
from rest_framework.views import APIView
1413

15-
class GithubSocialLogin(viewsets.ModelViewSet):
16-
http_method_names = ["post"]
14+
class GithubSocialLogin(APIView):
1715
permission_classes = (AllowAny,)
18-
serializer_class = GithubSerializer
19-
20-
def create(self, request, *args, **kwargs):
21-
serializer = self.get_serializer(data=request.data)
22-
serializer.is_valid(raise_exception=True)
2316

24-
code = serializer.data['code']
17+
def get(self, request):
18+
code = self.request.GET.get('code')
2519
client_id = getattr(settings, 'GITHUB_CLIENT_ID')
2620
client_secret = getattr(settings, 'GITHUB_SECRET_KEY')
2721
root_url = 'https://github.com/login/oauth/access_token'

api/routers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
ActiveSessionViewSet,
55
LogoutViewSet,
66
)
7-
from api.authentication.viewsets.social_login import GithubSocialLogin
87
from rest_framework import routers
98
from api.user.viewsets import UserViewSet
109

@@ -20,7 +19,6 @@
2019

2120
router.register(r"logout", LogoutViewSet, basename="logout")
2221

23-
router.register(r"github-login", GithubSocialLogin, basename="github-login")
2422

2523
urlpatterns = [
2624
*router.urls,

core/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
urlpatterns = [
66
path('admin/', admin.site.urls),
77
path("api/users/", include(("api.routers", "api"), namespace="api")),
8+
path("api/sessions/oauth/github/", GithubSocialLogin.as_view(), name="github_login"),
89
]

0 commit comments

Comments
 (0)