4

settings.py有:

SOCIAL_AUTH_VK_OAUTH2_SCOPE = ['email'] 

但它不起作用。同时我可以收到来自 Facebook 的电子邮件。

4

3 回答 3

3

Django (1.9) 和 python-social-auth (0.2.13)

设置.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',
)

网址.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->应用程序->设置:

site address: http://127.0.0.1:8000
redirect uri: http://127.0.0.1:8000/complete/vk-oauth2/
于 2015-12-24T14:30:04.870 回答
2

我刚刚找到了解决方法:

https://github.com/omab/python-social-auth/pull/267

此修复将在 0.1.23 之后添加到 pip distrib

于 2014-05-13T12:21:57.490 回答
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

于 2014-05-07T21:05:20.197 回答