django-allauth:将多个社交帐户链接到单个用户 [英] django-allauth: Linking multiple social accounts to a single user

查看:154
本文介绍了django-allauth:将多个社交帐户链接到单个用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In testing django-allauth, if I log in and log out with different social accounts, they don't seem to be linked together (in that I cannot access them by looking at socialaccount_set.all.0, socialaccount_set.all.1, etc).

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

Can someone explain how to link social accounts together?

我看过这篇文章:如何连接多个社会auth提供者使用django-allauth使用django-allauth?,这似乎使用户的用户首先登录一个社会帐户,然后链接其他帐户为自己。

I did see this post: how do i connect multiple social auth providers to the same django user using django-allauth? which seems to put the onus on the user to log in first with one social account, and then link the other accounts for himself.

当然,应该有办法做到这一点,而不必将使用者放在用户身上?也许通过电子邮件地址?

Certainly there should be a way to do this without putting the onus on the user? Maybe by email addresses?

现有用户的事实之后是否有办法?

Is there a way to do this after the fact with existing users?

推荐答案

如果您的用户已经登录,我已经使用标签 provider_login_url 并设置属性 process =connect。以下是为认证用户显示的块的代码段

If your user is already logged in, I've successfully connected another account using the tag provider_login_url and setting the attribute process="connect". Here is the code snippet to put in a block displayed for authenticated users:

{% 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 而不要忘记要求您的提供者范围内的电子邮件:

Set SOCIALACCOUNT_QUERY_EMAIL=True and don't forget to ask for the email in the scope of your providers:

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 。对我来说,自动关联登录和一个伟大的可用性增强就足够了。

I also want to know if it is possible to automatically associate a account using the email address. I can see in the column "extra_data" of the socialaccount_socialaccount table that both Google and Facebook send a "verified_email": true. For me it would be enough to automatically associate the logins and a great usability enhancement.

这篇关于django-allauth:将多个社交帐户链接到单个用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆