django - django-allauth:将多个社交帐户链接到单个用户

标签 django django-allauth

在测试django-allauth时,如果我使用不同的社交帐户登录和注销,它们似乎没有链接在一起(因为我无法通过查看socialaccount_set.all.0,socialaccount_set.all.1等访问它们) )。

有人可以解释如何将社交帐户关联在一起吗?

我确实看到了这篇文章:how do i connect multiple social auth providers to the same django user using django-allauth?,这似乎使用户有责任首先使用一个社交帐户登录,然后为自己链接其他帐户。

当然,应该有一种方法,而不会给用户带来负担?也许通过电子邮件地址?

现有用户事后有办法解决吗?

最佳答案

如果您的用户已经登录,那么我已经使用标签provider_login_url并设置了属性process="connect"成功连接了另一个帐户。这是放置在为经过身份验证的用户显示的块中的代码段:

{% load socialaccount %}
<p><a href="{% provider_login_url "facebook" process="connect" %}">Connect a facebook account</a></p>
<p><a href="{% provider_login_url "google" process="connect" %}">Connect a Google account</a></p>

设置SOCIALACCOUNT_QUERY_EMAIL=True,不要忘记在提供商的范围内索要电子邮件:
SOCIALACCOUNT_PROVIDERS = \
    {'facebook':
         {'SCOPE': ['email', ],
          'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
          'METHOD': 'oauth2',
          'LOCALE_FUNC': lambda request: 'pt_BR'},
     'google':
         {'SCOPE': ['https://www.googleapis.com/auth/userinfo.profile',
                    'email'],
          'AUTH_PARAMS': {'access_type': 'online'}
         },
}

我还想知道是否可以使用电子邮件地址自动关联帐户。我可以在socialaccount_socialaccount表的“extra_data”列中看到Google和Facebook都发送了"verified_email": true。对我而言,自动将登录名与极大的可用性增强关联就足够了。

关于django - django-allauth:将多个社交帐户链接到单个用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13140021/

相关文章:

django - 检查用户是否已使用社交帐户登录 - Django

python - 尽管迁移已成功完成,但 Admin 或 Api 没有发生任何更改

python - Django 使用整数参数从模板构建 URL,主键

python - django-pytest setup_method 数据库问题

python - mysql-python安装错误: Cannot open include file: 'config-win. h

Django 2.0 allauth Facebook 2018

python - 使用 ACCOUNT_FORMS 覆盖 Django allauth 登录表单

python - 测试 Django allauth

python - 类型错误 : tuple indices must be integers, 不是 str Python/django

python django allauth终端错误