I've followed through basic allauth installation docs so I have a basic Google, Facebook and username/password system working fine. What I'd like to do now is to automatically associate social accounts with an existing username + password account when a user attempts to login with the social account link.
There are many posts about this topic already, such as this and this but I'm stuck quite early on in the process.
As per those other posts, I've created a class that overrides DefaultSocialAccountAdapter and called it SocialAccountAdapter. I've then added it as a configuration setting to my settings.py file (where my_app is the name of my app inside INSTALLED_APPS):
ACCOUNT_ADAPTER = 'my_app.adapter.SocialAccountAdapter'
The class in question looks like the following.
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
class SocialAccountAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self, request, sociallogin):
pass
...in other words, it should do absolutely nothing more than the parent class. The problem is I get errors on the /accounts/login/ page.
File ".../site-packages/allauth/account/utils.py", line 41, in get_next_redirect_url if not get_adapter(request).is_safe_url(redirect_to): AttributeError: 'SocialAccountAdapter' object has no attribute 'is_safe_url'
So to 'fix' that, I added the following to the SocialAccountAdapter class:
def is_safe_url(self, url):
from django.utils.http import is_safe_url
return is_safe_url(url)
...but upon using the default form to enter in a username and password on the accounts/login page, I get the following error.
File ".../site-packages/allauth/account/forms.py", line 157, in clean user = get_adapter(self.request).authenticate( AttributeError: 'SocialAccountAdapter' object has no attribute 'authenticate'
If I try to follow one of the social login links e.g.:
{% provider_login_url provider.id openid=brand.openid_url process=process %})
...I get the following error.
File ".../site-packages/allauth/socialaccount/adapter.py", line 68, in new_user return get_account_adapter().new_user(request) TypeError: new_user() takes exactly 3 arguments (2 given)
Is there some basic setup procedure I've missed? According to the docs this should just be a simple override but something else is happening behind the scenes that I don't understand and is forcing me to add code I didn't expect to have to account for.