更新 - 我按照我为Twitch尝试的相同步骤让allauth与谷歌合作。
首先,我对编程任何东西都很陌生。这是我在教程之外的第一个项目。
我尝试使用django-allauth使用Twitch登录。我使用coockiecutter-django开始我的项目,自动设置django-allauth,但没有设置任何社交身份验证。我可以使用我网站上的帐户登录。
将&alcuth.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注册页面和我的管理页面中的所有信息都应该匹配。我复制/粘贴所有并多次检查。删除所有信息并再次输入。
答案 0 :(得分:2)
您需要添加user_read
范围,以便回调请求包含_id
参数
将此添加到您的settings.py
SOCIALACCOUNT_PROVIDERS = {
"twitch": {"SCOPE": ["user_read"]},
}