From 5527955f041d2026ed249a09f7afbfb6bf2475fb Mon Sep 17 00:00:00 2001 From: Zoran Sinnema Date: Wed, 12 May 2021 14:25:48 +0200 Subject: [PATCH] #193 chore: added oauth --- requirements.in | 3 +- requirements.txt | 3 +- scidash/account/static/css/main.css | 3 +- .../account/templates/registration/login.html | 31 +++++++--------- scidash/main/settings.py | 37 ++++++++++++++++++- scidash/main/urls.py | 5 ++- 6 files changed, 58 insertions(+), 24 deletions(-) diff --git a/requirements.in b/requirements.in index f7392fab..530e23a1 100644 --- a/requirements.in +++ b/requirements.in @@ -4,7 +4,7 @@ channels==2.1.2 djangorestframework==3.7.1 drf-writable-nested django-filter==1.1.0 -djangorestframework-jwt +# djangorestframework-jwt django-extensions django-dotenv rest-framework-cache @@ -19,3 +19,4 @@ wheel==0.33.6 sentry-sdk==1.0.0 django-ckeditor==5.9.0 django-admin-sortable2==0.7.5 +social-auth-app-django==4.0.0 diff --git a/requirements.txt b/requirements.txt index 0e823f8d..ff9a377a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,7 +31,7 @@ django-filter==1.1.0 django-material==1.5.2 django-timezone-field==3.0 # via django-celery-beat django==1.11.23 -djangorestframework-jwt==1.11.0 +# djangorestframework-jwt==1.11.0 djangorestframework==3.7.1 drf-writable-nested==0.5.1 git+git://github.com/scidash/neuronunit@metacell#egg=neuronunit @@ -98,6 +98,7 @@ redis==2.10.6 # via celery rest-framework-cache==0.1 sentry-sdk==1.0.0 six==1.12.0 # via autobahn, automat, django-extensions, pyhamcrest, python-dateutil, txaio +social-auth-app-django==4.0.0 twisted==18.9.0 # via daphne txaio==18.8.1 # via autobahn vine==1.3.0 # via amqp diff --git a/scidash/account/static/css/main.css b/scidash/account/static/css/main.css index ab45a818..3bc5fe47 100644 --- a/scidash/account/static/css/main.css +++ b/scidash/account/static/css/main.css @@ -68,10 +68,9 @@ body { .login-container { position: fixed !important; - top: 50%; + top: 40%; left: 50%; transform: translate(-50%, -50%) !important; - width: 250px; } .password-reset-container { diff --git a/scidash/account/templates/registration/login.html b/scidash/account/templates/registration/login.html index 7318c296..ab31db88 100644 --- a/scidash/account/templates/registration/login.html +++ b/scidash/account/templates/registration/login.html @@ -8,25 +8,22 @@
SCIDASH LOGIN

-
-
- {% csrf_token %} - {% form form=form %}{% endform %} - - -
-
-
-
- - + + - - + + -
-
- Go home + + + + Go home
{% endblock %} diff --git a/scidash/main/settings.py b/scidash/main/settings.py index 188ad4bc..714a27a4 100644 --- a/scidash/main/settings.py +++ b/scidash/main/settings.py @@ -71,6 +71,8 @@ 'django_db_logger', 'ckeditor', 'adminsortable2', + # Add the following django-allauth apps + 'social_django', ] SCIDASH_APPS = [ @@ -94,12 +96,43 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] +SOCIAL_AUTH_POSTGRES_JSONFIELD = True +SOCIAL_AUTH_URL_NAMESPACE = 'social' + +# see https://python-social-auth.readthedocs.io/en/latest/backends/index.html +# for configation of social backends + +# GOOGLE +# https://python-social-auth.readthedocs.io/en/latest/backends/google.html +# see https://developers.google.com/identity/protocols/oauth2?csw=1#Registering +# to get google client id (key) and secret +SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '732706977649-oou1hmc5q4mbrsida2bvu0mplmsebok0.apps.googleusercontent.com' +SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'WbtBzkxLVODaSi9PcPHS2DuL' + +# TWITTER +# https://python-social-auth.readthedocs.io/en/latest/backends/twitter.html +SOCIAL_AUTH_TWITTER_KEY = '' +SOCIAL_AUTH_TWITTER_SECRET = '' + +# GITHUB +# https://python-social-auth.readthedocs.io/en/latest/backends/github.html +SOCIAL_AUTH_GITHUB_KEY = '6e17b37f51445888e940' +SOCIAL_AUTH_GITHUB_SECRET = 'b920fd48bb6a057225989692bb5eacb84032bab5' + +AUTHENTICATION_BACKENDS = ( + 'social_core.backends.open_id.OpenIdAuth', + 'social_core.backends.google.GoogleOAuth2', + 'social_core.backends.twitter.TwitterOAuth', + 'social_core.backends.github.GithubOAuth2', + 'django.contrib.auth.backends.ModelBackend', +) + REST_FRAMEWORK = { # Use Django's standard `django.contrib.auth` permissions, # or allow read-only access for unauthenticated users. 'DEFAULT_AUTHENTICATION_CLASSES': [ 'scidash.account.auth.CsrfExemptSessionAuthentication', - 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' + # 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' ], 'DEFAULT_FILTER_BACKENDS': [ 'django_filters.rest_framework.DjangoFilterBackend' @@ -118,6 +151,8 @@ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', + 'social_django.context_processors.backends', + 'social_django.context_processors.login_redirect', 'django.contrib.messages.context_processors.messages', ], }, diff --git a/scidash/main/urls.py b/scidash/main/urls.py index f508b92b..11ef9151 100644 --- a/scidash/main/urls.py +++ b/scidash/main/urls.py @@ -19,7 +19,7 @@ from django.contrib.auth import views as auth_views from rest_framework.routers import DefaultRouter from rest_framework_cache.registry import cache_registry -from rest_framework_jwt.views import obtain_jwt_token +# from rest_framework_jwt.views import obtain_jwt_token from scidash.account.api.views import CheckIsLoggedView, \ UserViewSet, \ @@ -65,7 +65,8 @@ urlpatterns = [ url(r'^admin/', admin.site.urls), - url(r'^api/login/$', obtain_jwt_token), + # url(r'^api/login/$', obtain_jwt_token), + url('', include('social_django.urls', namespace='social')), url(r'^data/', include('scidash.general.urls')), url(r'^api/date-range/$', DateRangeView.as_view(), name='date-range-view'), url(r'^api/', include(router.urls)),