Skip to content

Commit

Permalink
#193 chore: added oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
zsinnema committed May 12, 2021
1 parent 22e21c4 commit 5527955
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 24 deletions.
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions scidash/account/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 14 additions & 17 deletions scidash/account/templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@
<div class="login-container">
<h5>SCIDASH LOGIN</h5>
<br>
<br>
<form method="POST">
{% csrf_token %}
{% form form=form %}{% endform %}
<input type="hidden" name="next" value="{% url 'index' %}">
<button type="submit" name="_submit" class="btn right">Login</button>
</form>
<br>
<br>
<br>
<a href="{% url 'sign-up' %}">
<button name="_signup" class="btn" style="float: left; letter-spacing: 0px;">Sign-up</button>
<a href="{% url 'social:begin' 'github' %}">
<button class="btn" style="float: left; letter-spacing: 0px; margin: 10px; width: 180px">
Login with GitHub
</button>
</a>
<a href="{% url 'password-reset' %}">
<button name="_reset" class="btn" style="float: right; letter-spacing: 0px;">Reset Password</button>
<a href="{% url 'social:begin' 'google-oauth2' %}">
<button class="btn" style="float: left; letter-spacing: 0px; margin: 10px; width: 180px">
Login with Google
</button>
</a>
<br>
<br>
<a href="{% url 'index' %}">Go home</a>
<a href="{% url 'social:begin' 'twitter' %}">
<button class="btn" style="float: left; letter-spacing: 0px; margin: 10px; width: 180px">
Login with Twitter
</button>
</a>
<a href="{% url 'index' %}" style="float: left; margin: 40px; width: 100%">Go home</a>
</div>
{% endblock %}

Expand Down
37 changes: 36 additions & 1 deletion scidash/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
'django_db_logger',
'ckeditor',
'adminsortable2',
# Add the following django-allauth apps
'social_django',
]

SCIDASH_APPS = [
Expand All @@ -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'
Expand All @@ -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',
],
},
Expand Down
5 changes: 3 additions & 2 deletions scidash/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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)),
Expand Down

0 comments on commit 5527955

Please sign in to comment.