Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting Existing User account to Social logged in user #233

Open
HabibUllahKhanBarakzai opened this issue Sep 16, 2020 · 5 comments
Open

Comments

@HabibUllahKhanBarakzai
Copy link

HabibUllahKhanBarakzai commented Sep 16, 2020

Hy, I am using django-rest-social-oauth2, and I need to handle the exceptional cases in which existing user wants to signin from facebook, so the current flow is that if the email is similar, it will create a new account by adding a random string to username when signing in from social login,

What I want to do is to associate the existing user account with the social login account, or may be not allow social login on existing user email, can you guide me on how I can achieve that.

Thanks

@carbogninalberto
Copy link

carbogninalberto commented Sep 23, 2020

Hi, I had a similar issue I simply added a pipeline in my settings.py file, for example mine is:

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.social_auth.associate_by_email',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)

in that way you force an existing user not to be created and moreover associate an existing one to the converted token; the executed code is then social_core.pipeline.user.py:

def create_user(strategy, details, backend, user=None, *args, **kwargs):
    if user:
        return {'is_new': False}

    fields = dict((name, kwargs.get(name, details.get(name)))
                  for name in backend.setting('USER_FIELDS', USER_FIELDS))
    if not fields:
        return

    return {
        'is_new': True,
        'user': strategy.create_user(**fields)
    }

@wagnerdelima
Copy link

Hi all.

My team and I are constantly using this framework and it seems it has died out there. I contacted the owner by email asking if he would add some of us as maintainers so we could continue to improve it. However we didn't get a response.

I am publishing the project under my profile and we are going to continue to invest time in it.

So I would like to gently ask you to contribute to this project on: https://github.com/wagnerdelima/drf-social-oauth2

Thank you for understanding.

@PrasanthPerumalsamy
Copy link

PrasanthPerumalsamy commented Aug 11, 2022

@carbogninalberto >
SOCIAL_AUTH_PIPELINE itself not creating a new user do i need to customize create_user function also as i mentioned?

@carbogninalberto
Copy link

I cannot recall the details of what I have done, but I don't think you need to customize the create_user function, but add the social_core.pipeline.user.create_user right after the social_core.pipeline.social_auth.associate_by_email. By the way, I kindly suggest you migrate to the project linked by @wagnerdelima because this one it's not supported anymore.

@LuisAngelN55
Copy link

Hi, I had a similar issue I simply added a pipeline in my settings.py file, for example mine is:

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.social_auth.associate_by_email',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)

in that way you force an existing user not to be created and moreover associate an existing one to the converted token; the executed code is then social_core.pipeline.user.py:

def create_user(strategy, details, backend, user=None, *args, **kwargs):
    if user:
        return {'is_new': False}

    fields = dict((name, kwargs.get(name, details.get(name)))
                  for name in backend.setting('USER_FIELDS', USER_FIELDS))
    if not fields:
        return

    return {
        'is_new': True,
        'user': strategy.create_user(**fields)
    }

This Works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants