400 error when using email only method for authentication using django-allauth and django-rest-auth

459 views Asked by At

I am trying to set up authentication using django-rest-auth and django-allauth. The user exists in the database and I can login to the django admin site. When I try to login using the rest-auth/login/ endpoint posting email/password, I receive a 400 error with the following response:

{
    "non_field_errors": [
        "Unable to log in with provided credentials."
    ]
}

I followed the instructions here: http://django-allauth.readthedocs.io/en/latest/configuration.html#configuration

In my settings file I have the following:

ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_AUTHENTICATION_METHOD = 'email' 

If I comment out the three lines above and use the same endpoint but add the username it works. It seems to only not work with email only mode.

Thanks for your help!

1

There are 1 answers

0
Marco Ferrantini On BEST ANSWER

I had the same issue, resolved by putting the right authentication backends. Here's my settings:

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True 

AUTHENTICATION_BACKENDS = (
    "django.contrib.auth.backends.ModelBackend",
    "allauth.account.auth_backends.AuthenticationBackend"
)