【问题标题】:python-social-auth with django. Can't get user email in VK.compython-social-auth 与 django。无法在 VK.com 中获取用户电子邮件
【发布时间】:2014-06-24 19:41:08
【问题描述】:

settings.py 有:

SOCIAL_AUTH_VK_OAUTH2_SCOPE = ['email'] 

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

【问题讨论】:

    标签: django email vk python-social-auth


    【解决方案1】:

    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->app->设置:

    site address: http://127.0.0.1:8000
    redirect uri: http://127.0.0.1:8000/complete/vk-oauth2/
    

    【讨论】:

    【解决方案2】:

    我刚刚找到了解决方法:

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

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

    【讨论】:

      【解决方案3】:

      我的猜测是您没有配置如何将范围数据映射到 SocialAuth 对象上的 extra_data dict:

      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

      【讨论】:

      • 感谢您的回答。你回答了,但对于另一种情况。它让我以正确的方式思考
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多