问题
My application must be accessed through an account like user@mydomain.com (Google managed email account)
First time I launch my application I can log in normally using that account. The problem starts when I log out (django log out) and try to login with my Gmail account (This is not allowed because of my email verification pipeline)
The first account is my user@mydomain.com and the second is my user@gmail.com account
I have a pipeline to verify if the user email belongs to my domain
Clicking on the @gmail.com account return an error from my pipeline
@partial
def require_mydomain_email(strategy, details, user=None, is_new=False, *args, **kwargs):
if user and user.email:
if '@mydomain' in user.email:
return
elif is_new and not details.get('email'):
email = strategy.request_data().get('email')
if email:
details['email'] = email
else:
current_partial = kwargs.get('current_partial')
return strategy.redirect(
'/email?partial_token={0}'.format(current_partial.token)
)
else:
email = details.get('email')
if email:
if '@mydomain' in email:
return
else:
current_partial = kwargs.get('current_partial')
messages.add_message(strategy.request, messages.WARNING, 'Your email must be an @mydomain email')
return strategy.redirect('/'.format(current_partial.token))
The Main problem:
After trying to log in with gmail.com account doesn't matter what account I'm trying to login after, my backend always receives the @gmail data from google.
Here are my pipeline settings:
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.mail.mail_validation',
'accounts.google_authentication.pipeline.require_psafe_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.debug.debug',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
'social_core.pipeline.debug.debug'
)
Any thoughts that may be helpful?
Edit1:
param details from my pipeline after run application (replaced personal data):
{'fullname': 'My Name', 'email': 'user@mydomain', 'first_name': 'Name', 'username': 'user.name', 'last_name': 'LastName'}
Then I log out,try to log in with my @gmail account (for testing porpuses):
{'fullname': 'My Full Name', 'email': 'myuser@gmail.com', 'first_name': 'MyName', 'username': 'username', 'last_name': 'Last Name'}
And even if I try to log in with user@mydomain.com again, I receive @gmail data
来源:https://stackoverflow.com/questions/44035052/django-social-auth-error-logging-in-with-two-email-accounts