Overview: Describe the social login settings using Google+ login as an example.
Assumption: Django is installed
Setting procedure:
Install the package for social login with the following command
pip install social-auth-app-django
Create a DB table with the following command
./manage.py migrate
Add the following to the configuration file (settings.py) created when you installed Django
INSTALLED_APPS = [
・ ・ ・
'social_django',
・ ・ ・
]
TEMPLATES = [
{
・ ・ ・
'OPTIONS': {
'context_processors': [
・ ・ ・
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_LOGIN_REDIRECT_URL =Transition destination after login
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY =Client ID
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET =Client secret
Set the URL
urlpatterns = [
・ ・ ・
url('', include('social_django.urls', namespace='social')),
]
Write the following in the template where you want to set up social login
<a href="{% url "social:begin" "google-oauth2" %}">Google+</a>
This completes the installation.
Recommended Posts