settings.py
有:
SOCIAL_AUTH_VK_OAUTH2_SCOPE = ['email']
但它不起作用。同时我可以从Facebook收到电子邮件。
答案 0 :(得分:3)
Django(1.9)和python-social-auth(0.2.13)
settings.py:
INSTALLED_APPS = [
...
'social.apps.django_app.default',
]
AUTHENTICATION_BACKENDS = (
'social.backends.vk.VKOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_RAISE_EXCEPTIONS = True
RAISE_EXCEPTIONS = True
SOCIAL_AUTH_VK_OAUTH2_KEY = 'id_app'
SOCIAL_AUTH_VK_OAUTH2_SECRET = 'secret_key'
SOCIAL_AUTH_VK_OAUTH2_SCOPE = [
'notify',
'friends',
'email',
]
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.social_auth.associate_by_email', # <--- enable this one
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
)
urls.py:
urlpatterns = [
...
url(r'', include('social.apps.django_app.urls', namespace='social')),
url(r'', include('django.contrib.auth.urls', namespace='auth')),
]
auth.html:
<a href="{% url 'social:begin' 'vk-oauth2' %}?next={% url 'dashboard' %}">VK</a>
VK-&GT; APP-&gt;设置:
site address: http://127.0.0.1:8000
redirect uri: http://127.0.0.1:8000/complete/vk-oauth2/
答案 1 :(得分:2)
答案 2 :(得分:1)
我的猜测是你没有配置如何将范围数据映射到extra_data
对象上的SocialAuth
字典:
SOCIAL_AUTH_VK_EXTRA_DATA = [ # configure how the data is labelled on SocialAuth.extra_data
# pattern is (source key, destination key)
('email', 'email'),
]
(可能是SOCIAL_AUTH_VK_OAUTH2_EXTRA_DATA
- 我猜这里基于其他后端)
也适用于Facebook:
SOCIAL_AUTH_FACEBOOK_SCOPE = [
'email', # we need to ask for this explicitly
]
SOCIAL_AUTH_FACEBOOK_EXTRA_DATA = [
# pattern is (source key, destination key)
('email', 'email'),
]
http://python-social-auth.readthedocs.org/en/latest/backends/facebook.html