使用仅电子邮件方法使用 django-allauth 和 django-rest-auth 进行身份验证时出现 400 错误

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

我正在尝试使用 django-rest-auth 和 django-allauth 设置身份验证。用户存在于数据库中,我可以登录到 django 管理站点。当我尝试使用 rest-auth/login/ 端点发布 email/password 登录时,我收到一个 400 错误,响应如下:

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

我按照此处的说明操作:http://django-allauth.readthedocs.io/en/latest/configuration.html#configuration

在我的设置文件中有以下内容:

ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_AUTHENTICATION_METHOD = 'email' 

如果我注释掉上面的三行并使用相同的端点但添加用户名,它就可以工作。它似乎只不适用于仅电子邮件模式。

感谢您的帮助!

我遇到了同样的问题,通过设置正确的身份验证后端解决了。这是我的设置:

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"
)