2
votes

I recently added an extra authentication backend to allow users to login using either their email address or username, but it seems to break django-social-auth since after enabling it, when I try to login through Facebook, I get the message Incorrect authentication service

The backend's code is:

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

I got the code snippet from Django snippets

My AUTHENTICATION_BACKENDS:

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.twitter.TwitterBackend',
    'social_auth.backends.facebook.FacebookBackend',
    'apps.members.backends.EmailBackend',
)
1

1 Answers

1
votes

I've successfully used an email auth backend with django-social-auth. I don't remember having done anything special for it to work so it might be something non obvious, here are the only differences I can see with my code :

I had my Email backend defined first in he list of AUTHENTICATION_BACKENDS, which may have some importance here.

I did not define any of the supports_object_permissions supports_anonymous_user supports_inactive_user.