RealmTeam / django-rest-framework-social-oauth2

python-social-auth and oauth2 support for django-rest-framework
MIT License
1.06k stars 191 forks source link

Email not being sent when trying to convert a Facebook token #23

Closed diegoponciano closed 8 years ago

diegoponciano commented 8 years ago

I followed the guide to configure Facebook auth, but as I tried to convert an external token using curl, I noticed only username is being sent on kwargs (and email is required in my model).

Possibly relevant stacktrace:

File ".../lib/python2.7/site-packages/social/pipeline/user.py", line 70, in create_user
    'user': strategy.create_user(**fields)
  File ".../lib/python2.7/site-packages/social/strategies/base.py", line 55, in create_user
    return self.storage.user.create_user(*args, **kwargs)
  File .../lib/python2.7/site-packages/social/storage/django_orm.py", line 60, in create_user
    return cls.user_model().objects.create_user(*args, **kwargs)
  File ".../myapp/models/user.py", line 55, in create_user
    return self._create_user(email, password, False, False, **extra_fields)
  File ".../myapp/models/user.py", line 36, in _create_user
    raise ValueError('The given email must be set')
ValueError: The given email must be set
PhilipGarnero commented 8 years ago

If you need to get the email from facebook, you'll need to add SOCIAL_AUTH_FACEBOOK_SCOPE = ['email'] in your settings to get the email as an additionnal information from facebook.

Normally, python-social-auth will take care of filling your user's email with it automatically. If you want to associate users by email you'll need to add 'social.pipeline.social_auth.associate_by_email' to your SOCIAL_AUTH_PIPELINE.

I'm closing this, feel free to reopen if you need more informations.

baneizalfe commented 8 years ago

@PhilipGarnero can you provide corrct setting for SOCAIL_AUTH_PIPELINE?

after adding

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.associate_by_email'
)

I get

TypeError at /api/auth/convert-token/
argument of type 'NoneType' is not iterable
PhilipGarnero commented 8 years ago

SOCIAL_AUTH_PIPELINE is a tuple already defined with python-social-auth. You must copy the default value and insert 'social.pipeline.social_auth.associate_by_email' in the list.