Skip to content

Instantly share code, notes, and snippets.

@ankit11421
Created March 1, 2019 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankit11421/c42bd61601f6cc66896e519af8f91227 to your computer and use it in GitHub Desktop.
Save ankit11421/c42bd61601f6cc66896e519af8f91227 to your computer and use it in GitHub Desktop.
SocialAuth
1. pip install social-auth-app-django
2.
Add the social_django to your INSTALLED_APPS
3.
python manage.py migrate
url(r'^oauth/', include('social_django.urls', namespace='social')),
4.
LOGIN_URL = 'login'
LOGOUT_URL = 'logout'
LOGIN_REDIRECT_URL = 'home'
5.
Update the MIDDLEWARE_CLASSES by adding the SocialAuthExceptionMiddleware to the end of it
'social_django.middleware.SocialAuthExceptionMiddleware'
6.
Now we update the context_processors inside TEMPLATE:
'social_django.context_processors.backends'
'social_django.context_processors.login_redirect'
7.
AUTHENTICATION_BACKENDS = (
'social_core.backends.github.GithubOAuth2',
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
8.
GOTO
https://github.com/settings/applications/new
9.
SOCIAL_AUTH_GITHUB_KEY = '#YOUR KEY'
SOCIAL_AUTH_GITHUB_SECRET = '#YOUR SECRET KEY'
10.
{% extends 'posts/base.html' %}
{% block content %}
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
<br>
<p><strong>-- OR --</strong></p>
<a href="{% url 'social:begin' 'github' %}">Login with GitHub</a><br>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment