更新- Twitch で試したのと同じ手順に従って、Google で allauth を使用できるようになりました。
まず、私は何かをプログラミングするのはまったく初めてです。これは、チュートリアル以外の私の最初のプロジェクトです。
Twitch を使用してログインするために django-allauth を使用しようとしています。django-allauth を自動的にセットアップする coockiecutter-django を使用してプロジェクトを開始していますが、ソーシャル認証はセットアップされていません。サイトで作成したアカウントで問題なくログインできます。
「allauth.socialaccount.providers.twitch」を INSTALLED_APPS に追加すると、ログイン ページに Twitch リンクが表示されます。http://www.twitch.tv/kraken/oauth2/clients/newでアプリを登録し、すべてを管理ソーシャル アプリケーション ページにコピーしました。
Twitch のログイン リンクをクリックすると、次のエラーが表示されます。
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/twitch/login/callback/?code=8lhhsf461v7ksw0no3ajlwfslbdtia&scope=&state=xxKe31qCbow2
Django Version: 1.7.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'crispy_forms',
'avatar',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.twitch',
'users',
'debug_toolbar')
Installed Middleware:
('djangosecure.middleware.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/home/brian/Envs/trycookie/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/brian/Envs/trycookie/local/lib/python2.7/site-packages/allauth/socialaccount/providers/oauth2/views.py" in view
53. return self.dispatch(request, *args, **kwargs)
File "/home/brian/Envs/trycookie/local/lib/python2.7/site-packages/allauth/socialaccount/providers/oauth2/views.py" in dispatch
102. response=access_token)
File "/home/brian/Envs/trycookie/local/lib/python2.7/site-packages/allauth/socialaccount/providers/twitch/views.py" in complete_login
21. extra_data)
File "/home/brian/Envs/trycookie/local/lib/python2.7/site-packages/allauth/socialaccount/providers/base.py" in sociallogin_from_response
45. uid = self.extract_uid(response)
File "/home/brian/Envs/trycookie/local/lib/python2.7/site-packages/allauth/socialaccount/providers/twitch/provider.py" in extract_uid
25. return str(data['_id'])
Exception Type: KeyError at /accounts/twitch/login/callback/
Exception Value: '_id'
関連すると思われるプロジェクト コードのすべてを提供するようにします。私が何かを忘れている場合は、私に知らせてください。
settings.py (coockiecutter-django では common.py に名前が変更されました)
INSTALLED_APPS = (
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.twitch',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",
)
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
)
SITE_ID = 1
ACCOUNT_AUTHENTICATION_METHOD = "username"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
AUTH_USER_MODEL = "users.User"
LOGIN_REDIRECT_URL = "users:redirect"
LOGIN_URL = "account_login"
urls.py
url(r'^users/', include("users.urls", namespace="users")),
url(r'^accounts/', include('allauth.urls')),
Twitch 登録ページと私の管理ページのすべての情報が一致している必要があります。すべてコピー&ペーストして、何度か確認しました。すべての情報を削除して、もう一度入力します。