我最近添加了一个额外的身份验证后端,以允许用户使用他们的电子邮件地址或用户名登录,但它似乎破坏了 django-social-auth,因为在启用它之后,当我尝试通过 Facebook 登录时,我收到了消息Incorrect authentication service
后端的代码是:
class EmailBackend:
supports_object_permissions = False
supports_anonymous_user = False
supports_inactive_user = False
def authenticate(self, username=None, password=None):
if email_re.search(username):
try:
user = User.objects.get(email=username)
except User.DoesNotExist:
return None
else:
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
return None
if user.check_password(password):
return user
return None
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
我的 AUTHENTICATION_BACKENDS:
AUTHENTICATION_BACKENDS = (
'social_auth.backends.twitter.TwitterBackend',
'social_auth.backends.facebook.FacebookBackend',
'apps.members.backends.EmailBackend',
)