3

I am using my corporate account (which is "Google for works" account) to implement Google oauth2.0 login in to my django application.

Pipeline in "settings.py" looks like:

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.associate_by_email',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
]

Adding conditional backends to pipepline.

if config.GCPAuthentication.AUTO_CREATE_ACCOUNTS:
    SOCIAL_AUTH_PIPELINE.extend([
    'social.pipeline.user.get_username',
    'social.pipeline.user.create_user'
])

While trying to login for the very first time with a new user, I am getting error: AttributeError at /complete/google-oauth2/: 'NoneType' object has no attribute 'provider'

And interestingly, user is getting created and saved in DB and on next login attempt it allows me to login.

Its throwing error here : https://github.com/omab/python-social-auth/blob/master/social/actions.py#L70

My corporate Google account might not have any social account(Google+ is disabled)/related info associated with it. Is that an issue?

In any case, can you please tell me any workaround to get rid of this issue?

Nitin Verma
  • 206
  • 2
  • 14
  • what do get_username() and create_user() return? – lukeaus Aug 11 '16 at 08:46
  • How can I check that? In the users, the new user getting created with username as my email ID, this is because i have, SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True in settings.py – Nitin Verma Aug 11 '16 at 10:28
  • I changed the sequence of functions pipeline and it worked: I guess it should follow the way it is mentioned here: https://github.com/omab/python-social-auth/blob/master/docs/pipeline.rst Thanks @luke_aus. – Nitin Verma Aug 11 '16 at 11:44

4 Answers4

4

The pipeline expects to follow the order in which functions needs to be called. To my solution right sequence should be like:

SOCIAL_AUTH_PIPELINE = [  # Note: Sequence of functions matters here.
    'social.pipeline.social_auth.social_details',  # 0
    'social.pipeline.social_auth.social_uid',  # 1
    'social.pipeline.social_auth.auth_allowed',  # 2
    'social.pipeline.social_auth.social_user',  # 3
    'social.pipeline.user.get_username',  # 4
    'social.pipeline.social_auth.associate_by_email',  # 5
    'social.pipeline.social_auth.associate_user',  # 6
    'social.pipeline.social_auth.load_extra_data',  # 7
    'social.pipeline.user.user_details',  # 8
]

# Adding conditional functions to pipepline.
# NOTE: Sequence of functions matters here.
if config.GCPAuthentication.AUTO_CREATE_ACCOUNTS:
    SOCIAL_AUTH_PIPELINE.insert(6, 'social.pipeline.user.create_user')
Nitin Verma
  • 206
  • 2
  • 14
  • I am facing similar problem. My pipeline order is same as above and have added a custom pipeline 'create_user_account' after 'user_details'. Both 'request' and 'user' are absent in the 'request' object passed to this pipeline. http://stackoverflow.com/questions/38973264/on-upgrading-python-social-auth-from-0-1-17-to-0-2-4-session-attribute-is-not-p – Sid Aug 22 '16 at 06:53
  • This may be because user_details function doesn't pass anything to next function in pipeline. As per your requirement you might need to change the order of functions in your pipeline: https://github.com/omab/python-social-auth/blob/master/social/pipeline/user.py#L75 – Nitin Verma Aug 22 '16 at 06:59
1

Yes you are right, Sequence of the function in the pipeline matters here as return of one function will be input to the next function in pipeline.

gcpexpert
  • 21
  • 2
0

As a sidenote I want to add that I faced a similar issue when I updated my USER model by changing it's primary key. In such scenarios, simply running migrations for the new USER model will not suffice. You will have to run migrations for the social auth as well. I did it by complete & forced migration of the entire project.

rahulthakur319
  • 455
  • 4
  • 16
0

I had the same error coming from a corrupted local DB. I had to cleanup the tables: social_auth_usersocialauth and django_session.

obotezat
  • 1,041
  • 16
  • 20