Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions api/authentication/serializers/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,3 @@ def validate(self, data):
}


class GithubSerializer(serializers.Serializer):
code = serializers.CharField(max_length=255)

16 changes: 5 additions & 11 deletions api/authentication/viewsets/social_login.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 0 additions & 2 deletions api/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,7 +19,6 @@

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

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

urlpatterns = [
*router.urls,
Expand Down
1 change: 1 addition & 0 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]