0

I'm trying to get the following module called from my pipeline:

def add_account(backend, details, response, user=None, is_new=False, *args, **kwargs):
    print ("testing")
    if is_new:
        Account.objects.create(id=user.id)

with my pipeline settings in my settings.py as:

SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.user.get_username',
'social_auth.backends.pipeline.user.create_user',
'Credit_Ledger.pipeline.add_account'
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',

'social_auth.backends.pipeline.user.update_user_details', )

Alex Creamer
  • 29
  • 1
  • 4

1 Answers1

0

You have to replace exist create_user pipeline if you want custom user creation behavior, but your code looks weird if you need just change default User model then it's redundant, you need just set AUTH_USER_MODEL and that's it.

If you need extract some extra data for new user, then add something like this:

def save_profile(backend, user, response, *args, **kwargs):
    if backend.name == "facebook":
        save_facebook_profile(user, response, **kwargs)

    elif backend.name == "google-oauth2":
        save_google_profile(user, response, **kwargs)

    else:
        return  # Unspecified backend

    user.social = True
    user.save()


def save_google_profile(user, response, **kwargs):
    if response.get("image"):
        if not user.avatar_image and not user.avatar_url:
            user.avatar_url = response.get("image").get("url")

    # Handle other fields

and in settings:

SOCIAL_AUTH_PIPELINE = (
    'social_auth.pipeline.social_auth.social_details',
    'social_auth.pipeline.social_auth.social_uid',
    'social_auth.pipeline.social_auth.auth_allowed',
    'social_auth.pipeline.social_auth.social_user',
    'social_auth.pipeline.user.get_username',
    'social_auth.backends.pipeline.user.create_user',
    'accounts.pipeline.save_profile',  # here is new pipeline behavior
    'social_auth.pipeline.social_auth.associate_user',
    'social_auth.pipeline.social_auth.load_extra_data',
    'social_auth.pipeline.user.user_details',
)

for more details: http://python-social-auth-docs.readthedocs.io/en/latest/pipeline.html

Andrey
  • 66
  • 6
  • I'm not sure how to replace the default create_user pipeline. I don't see it in the documentation either. – Alex Creamer Sep 03 '17 at 15:35
  • just look at default create_user implementation of create_user and create own: https://github.com/python-social-auth/social-core/blob/master/social_core/pipeline/user.py#L64 – Andrey Sep 03 '17 at 16:17
  • How do I ensure it will only get called whenever a user is created – Alex Creamer Sep 03 '17 at 18:06
  • I don't need to replace the default user model. Can you tell me why print("testing") isn't being called? – Alex Creamer Sep 03 '17 at 18:36