Search code examples
djangopython-social-auth

python social auth: get email from Google OAuth2


I configured the login with google in a Django project. I'm able to get the name and last name but the user is saved with an empty email. I configured the scope in this way:

SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
    'profile',
    'email'
]

But the email continues saving as "". Am I writing the scopes in bad way?


Solution

  • Try this

    SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
    'https://www.googleapis.com/auth/userinfo.email',
    'https://www.googleapis.com/auth/userinfo.profile'
    ]
    

    it will collect user email and profile name store it into USER model.