1

I am using Django allauth for providing social login using GitHub and google. I have users already registered. I have to log in the users based on their emails. Firstly I tried authenticating with google, and it redirected me to a link /accounts/social/signup/

It prompted me a form with username and email of the user (the email column is already filled). If I give some username and click submit it creates a new user of that form. Instead of logging the current user. I am not understanding where the flaw is

settings.py code --

SOCIALACCOUNT_QUERY_EMAIL = True
ACCOUNT_AUTHENTICATION_METHOD='email'
ACCOUNT_EMAIL_REQUIRED = True
SOCIALACCOUNT_PROVIDERS = \
{'github': {
    'SCOPE': [
        'email',
    ],
  'google':
     {'SCOPE': ['https://www.googleapis.com/auth/userinfo.profile',
                'email'],
      'AUTH_PARAMS': {'access_type': 'online'}
     },
}

I am trying to login users based on their emails. Am I wrong at any point ??

My Login template

<a href="{% provider_login_url 'google' process='login' %}" class="connect google">
<a href="{% provider_login_url 'github' process='login' %}" class="connect github">

It is actually performing the operation of signup every time instead of login. How actually to prevent it and login users based on email?

Thanks!!

rammanoj
  • 479
  • 8
  • 26
  • Duplicate of: https://stackoverflow.com/questions/28897220/django-allauth-social-account-connect-to-existing-account-on-login#28911917 – dirkgroten Aug 21 '18 at 15:02
  • hey thanks @dirkgroten for the help. But a small issue is there any way to get the details of user (return details from callback url ) in django adapters. More specifically, I am currently using django pre_social_login adapter as specified in above link. So is there any way to get the user details returned from third party accounts instead of using details is SocialAccount modal ? – rammanoj Sep 03 '18 at 12:52
  • The `pre_social_login` signal passes two parameters to your callback. Beside the `request` you also get the `SocialLogin` object. `sociallogin.account` is a `SocialAccount` object, which has an `extra_data` attribute that contains all the attributes gathered from the 3rd party. So `sociallogin.account.extra_data` is what you should look into. – dirkgroten Sep 03 '18 at 13:01
  • Thanks @dirkgroten for reply. But what if there is user is logging for the first time? I guess it does not have any information in Sociallogin.account ? Please correct me if I am wrong ? – rammanoj Sep 03 '18 at 13:10
  • Set a breakpoint in your `pre_social_login` callback, I'm pretty sure the `SocialAccount` object is already created when you get there, albeit probably not yet saved to the DB (`.pk = None`). – dirkgroten Sep 03 '18 at 13:11
  • thanks @dirkgroten – rammanoj Sep 03 '18 at 16:29

0 Answers0