Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-rest-auth authentication not working

I wanted a simple api authentication route using django-rest-framework and 'django-rest-auth`. The register part is working fine as confirmed by the default django admin console and i can also see the users. Unluckily the api authentication keeps on returning me with error

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

Currently the configuration that i have for my allauth is as follows

# all-auth configuration
ACCOUNT_EMAIL_REQUIRED=True
ACCOUNT_AUTHENTICATION_METHOD="email"
ACCOUNT_USERNAME_REQUIRED=False
ACCOUNT_EMAIL_VERIFICATION="none"
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE=False

# CORS Configuration
CORS_ORIGIN_ALLOW_ALL=True

I am unsure what part I am missing. Please guide me in the right direction. There are no errors and the response code is 400. The credentials are correct as verified from django admin panel. Thanks in advance

Update

The problem is somewhat with email. I commented the configuration out and tried to generate a token with username and password. That works without any error.

like image 699
georoot Avatar asked Jan 18 '17 12:01

georoot


People also ask

How do I use authentication credentials in Django?

from django.contrib.auth import authenticate, login def my_view(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) if user is not None: login(request, user) # Redirect to a success page. ... else: # Return an 'invalid ...


1 Answers

You need to add these backends to settings.py file

AUTHENTICATION_BACKENDS = (
   "django.contrib.auth.backends.ModelBackend",
   "allauth.account.auth_backends.AuthenticationBackend"
)
like image 183
Mohamed El-Saka Avatar answered Sep 25 '22 03:09

Mohamed El-Saka