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?
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?
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>
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'}
},
}
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.
Certainly there should be a way to do this without putting the onus on the user? Maybe by email addresses?
Be very very careful about how you do this. You may be opening a huge security hole. If you don't put some onus on the user and just auto-link accounts with the same email address you introduce the following attack vector:
You can take steps to reduce this risk, but even if all providers require email confirmation now, any slip-up in the 3rd party teams would then open this hole in your security.
Maybe for what you're doing the risk is merited, just please be careful. A bit of onus on the user is probably not the worst thing.
I've seen flows where it suggests an auto-match, then asks you for your password or to re-authenticate with one of the original providers to add the new account to your original account. These wouldn't have the same potential to exploit, but have some brain-f*ck level corner cases and UI complications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With