Django社交身份验证错误使用两个电子邮件帐户登录

时间:2017-05-17 21:27:27

标签: python django email google-oauth2 django-socialauth

我的应用程序必须通过 user@mydomain.com (Google托管电子邮件帐户)等帐户进行访问

我第一次启动应用程序时,可以使用该帐户正常登录。 当我退出(django注销)并尝试使用我的Gmail帐户登录时,问题就出现了(由于我的电子邮件验证管道,这是不允许的)

第一个帐户是 user@mydomain.com ,第二个帐户是 user@gmail.com 帐户

Email accounts

我有一个管道来验证用户电子邮件是否属于我的域

点击 @ gmail.com 帐户会从我的管道返回错误

@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))

主要问题:

尝试使用 gmail.com 帐户登录后无论我尝试登录的是哪个帐户,我的后端始终会收到来自 @gmail 的数据谷歌。

以下是我的管道设置:

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'
)

任何可能有用的想法?

EDIT1:

在运行应用程序(替换个人数据)后从我的管道中获取详细信息:

{'fullname': 'My Name', 'email': 'user@mydomain', 'first_name': 'Name', 'username': 'user.name', 'last_name': 'LastName'}

然后我退出,尝试使用我的@gmail帐户登录(用于测试porpuses):

{'fullname': 'My Full Name', 'email': 'myuser@gmail.com', 'first_name': 'MyName', 'username': 'username', 'last_name': 'Last Name'}

即使我尝试再次使用 user@mydomain.com 登录,我也会收到 @gmail 数据

0 个答案:

没有答案