Skip to content

Commit

Permalink
Django API endpoint for OAuth with allauth and dj-rest-auth #5
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueberryBuns committed Apr 22, 2021
1 parent f1b393b commit c279c18
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Binary file modified meeting_scheduler/db.sqlite3
Binary file not shown.
11 changes: 7 additions & 4 deletions meeting_scheduler/meeting_scheduler/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']


# Application definition
Expand All @@ -43,7 +43,7 @@
'corsheaders',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'dj_rest_auth',

#Custom applications
'scheduler_api',
Expand All @@ -58,7 +58,7 @@
'allauth.socialaccount.providers.google',
]

SITE_ID = 1
SITE_ID = 2

# Provider specific settings
SOCIALACCOUNT_PROVIDERS = {
Expand Down Expand Up @@ -199,6 +199,9 @@
],
}

CORS_ORIGIN_ALLOW_ALL = True

CORS_ALLOWED_ORIGINS = [
"http://localhost:3000",
]
]

6 changes: 2 additions & 4 deletions meeting_scheduler/meeting_scheduler/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
"""
from django.contrib import admin
from django.urls import path, include
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
from scheduler_api.views import GoogleLogin


urlpatterns = [
path('admin/', admin.site.urls),
path('', include('scheduler.urls', namespace='scheduler')),
path('api/', include('scheduler_api.urls', namespace='scheduler_api')),
path('auth/', include('rest_framework.urls', namespace='rest_framework')), #Mock
path('accounts/', include('allauth.urls')),
path('rest-auth/google/', GoogleLogin.as_view(), name='google-login')
#path('accounts/', include('allauth.urls')),
]
11 changes: 6 additions & 5 deletions meeting_scheduler/scheduler_api/views.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from rest_framework.decorators import parser_classes, api_view, permission_classes
from rest_framework.parsers import JSONParser
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_auth.registration.views import SocialLoginView
from rest_framework.permissions import IsAuthenticatedOrReadOnly, AllowAny
from dj_rest_auth.registration.views import SocialLoginView

from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter

@api_view(['POST'])
@parser_classes([JSONParser])
@permission_classes([AllowAny])
def google_data(request, format=None):
print (f'XDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD received data: {request.data}')
return Response({'received data': request.data})
print (f'XDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD received data: {request}')
return Response({'received data': request})

@api_view(['GET'])
@parser_classes([JSONParser])
@permission_classes([IsAuthenticated])
@permission_classes([AllowAny])
def google_data(request, format=None):
content ={
'status':'request was permitted'
Expand Down

0 comments on commit c279c18

Please sign in to comment.