Skip to content

Commit 0281fdd

Browse files
committed
added github auth
1 parent ba83a56 commit 0281fdd

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

django_school/django_school/settings.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'django.contrib.humanize',
4343

4444
'crispy_forms',
45-
45+
'social_django',
4646
'classroom',
4747
]
4848

@@ -54,6 +54,8 @@
5454
'django.contrib.auth.middleware.AuthenticationMiddleware',
5555
'django.contrib.messages.middleware.MessageMiddleware',
5656
'django.middleware.clickjacking.XFrameOptionsMiddleware',
57+
58+
'social_django.middleware.SocialAuthExceptionMiddleware',
5759
]
5860

5961
ROOT_URLCONF = 'django_school.urls'
@@ -71,6 +73,9 @@
7173
'django.template.context_processors.request',
7274
'django.contrib.auth.context_processors.auth',
7375
'django.contrib.messages.context_processors.messages',
76+
77+
'social_django.context_processors.backends', # <--
78+
'social_django.context_processors.login_redirect', # <--
7479
],
7580
},
7681
},
@@ -123,21 +128,27 @@
123128
]
124129

125130

126-
# Custom Django auth settings
131+
AUTHENTICATION_BACKENDS = [
132+
'social_core.backends.github.GithubOAuth2',
133+
# 'social_core.backends.twitter.TwitterOAuth',
134+
# 'social_core.backends.facebook.FacebookOAuth2',
135+
136+
'django.contrib.auth.backends.ModelBackend',
137+
]
138+
139+
SOCIAL_AUTH_GITHUB_KEY = '19c198d4322457e5917e'
140+
SOCIAL_AUTH_GITHUB_SECRET = '1bd51b62009a516e2071cb5b9c851f4cde89c8a3'
127141

142+
# Custom Django auth settings
128143
AUTH_USER_MODEL = 'classroom.User'
129144

130145
LOGIN_URL = 'login'
131-
132146
LOGOUT_URL = 'logout'
133-
134147
LOGIN_REDIRECT_URL = 'home'
135-
136148
LOGOUT_REDIRECT_URL = 'home'
137149

138150

139151
# Messages built-in framework
140-
141152
MESSAGE_TAGS = {
142153
messages.DEBUG: 'alert-secondary',
143154
messages.INFO: 'alert-info',
@@ -148,5 +159,4 @@
148159

149160

150161
# Third party apps configuration
151-
152162
CRISPY_TEMPLATE_PACK = 'bootstrap4'

django_school/django_school/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
path('accounts/signup/', classroom.SignUpView.as_view(), name='signup'),
1212
path('accounts/signup/student/', students.StudentSignUpView.as_view(), name='student_signup'),
1313
path('accounts/signup/teacher/', teachers.TeacherSignUpView.as_view(), name='teacher_signup'),
14+
path('oauth/', include('social_django.urls', namespace='social')), # <--
1415
]

django_school/templates/registration/login.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ <h2>Log in</h2>
2323
{{ form.password|as_crispy_field }}
2424
<button type="submit" class="btn btn-primary">Log in</button>
2525
</form>
26+
<br>
27+
<p><strong>-- OR --</strong></p>
28+
<a href="{% url 'social:begin' 'github' %}">Login with GitHub</a><br>
2629
</div>
2730
</div>
2831
{% endblock %}

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Django==3.0.4
22
django-crispy-forms==1.9.0
3+
social-auth-app-django==3.1.0

0 commit comments

Comments
 (0)