[PYTHON] Set up social login with Django

Overview: Describe the social login settings using Google+ login as an example.

GitHub page Documentation

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

Set up social login with Django
Login with django rest framework
Set up pygit2 with static link
Set up a web server with CentOS7 + Anaconda + Django + Apache
Set up a Samba server with Docker
Creating a login screen with Django allauth
Internationalization with django
CRUD with Django
Set up a simple HTTPS server with asyncio
Set up a local server with Go-File upload-
Set up golang with goenv on GNU / Linux
Set up a local server with Go-File download-
A story about implementing a login screen with django
Authenticate Google with Django
Django 1.11 started with Python3.6
Upload files with Django
Output PDF with Django
Markdown output with Django
Use Gentelella with django
I set up Django from scratch (Vagrant, Centos, Python3)
Twitter OAuth with Django
Getting Started with Django 1
Set up Docker on Oracle Linux (7.x) with Vagrant
Send email with Django
File upload with django
Set up Jetson nano
Use LESS with Django
Pooling mechanize with Django
Launch Django on a Docker container with docker-compose up
Use MySQL with Django
Start today with Django
Set up a Python development environment with Sublime Text 2
[Vagrant] Set up a simple API server with python
Getting Started with Django 2
Set up a Python development environment with Visual Studio Code
Reload the server set up with gunicorn when changing the code
Create a social integration API for smartphone apps with Django
Set up Python 3.4 on Ubuntu
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Get started with Django! ~ Tutorial ⑤ ~
Set connection timeout with boto3
Minimal website environment with django
Create an API with Django
Do Django with CodeStar (Python3.8, Django2.1.15)
Deploy Django serverless with Lambda
Python3 + Django ~ Mac ~ with Apache
Set Up for Mac (Python)
Getting Started with Python Django (1)
Create a homepage with django
Get started with Django! ~ Tutorial ④ ~
Getting Started with Python Django (4)
Web application creation with Django
Getting Started with Python Django (3)
Combine FastAPI with Django ORM
Get started with Django! ~ Tutorial ⑥ ~
Save tweet data with Django
Create a Django login screen
Set up Polyglot on Windows
Do AES encryption with DJango
Getting Started with Python Django (6)
Easy proxy login with django-hijack