Help us understand the problem. What is going on with this article?

Djangoでソーシャルログインを設定する

More than 3 years have passed since last update.

概要:
Google+のログインを例としたソーシャルログインの設定を記述します。

GitHubのページ
ドキュメント

前提:
Djangoがインストールされていること

設定の手順:

下記コマンドでソーシャルログイン用のパッケージをインストール

pip install social-auth-app-django

下記コマンドでDBテーブルを作成する

./manage.py migrate

Djangoをインストールした時にできた設定ファイル(settings.py)に下記を追加していく

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 = ログイン後の遷移先
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = クライアントID
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = クライアントシークレット

URLの設定をする

urlpatterns = [
    ・・・
    url('', include('social_django.urls', namespace='social')),
]

ソーシャルログインを設置したいテンプレートに下記を記述

<a href="{% url "social:begin" "google-oauth2" %}">Google+</a>

以上で、設置完了。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした