Question

settings.py has:

SOCIAL_AUTH_VK_OAUTH2_SCOPE = ['email'] 

But it doesn't work. Simultanously I can get email from Facebook.

Was it helpful?

Solution 2

I have just found how to fix it:

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

This fix will be added to pip distrib after 0.1.23

OTHER TIPS

Django (1.9) and 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->settings:

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

My guess is you're not configuring how to map the scoped data to the extra_data dict on the SocialAuth object:

SOCIAL_AUTH_VK_EXTRA_DATA = [  # configure how the data is labelled on SocialAuth.extra_data
    # pattern is (source key, destination key)
    ('email', 'email'),
]

(It may be SOCIAL_AUTH_VK_OAUTH2_EXTRA_DATA – I am guessing here based on other backends)

Also for 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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top