1

I have setuped django-rest-framework and its basic users/groups api as described here: http://www.django-rest-framework.org/. While I can see users and groups via the api, I can't log in. There is /api-auth/login page and whenever I insert un & passwd and submit it just redirects to the same page without any renderred message. I wonder what I am missing. How can I "log in" into the API.

2 Answers 2

1

Django rest framework support different methods of authentification. Not sure what you mean by /api-auth/. There is no such standard url in this framework. Please check documentation to see what methods of authentication are possible and how to do it.

Sign up to request clarification or add additional context in comments.

4 Comments

If you go on the provided link in the question and search for 'api-auth', you will find out what I meant. Anyway it was my fault that I incorrectly replaced Authentication backend for my own.
Well i did the search. There is no api-auth on the link i provided. As well as there is no api-auth in the source code of django-rest-framework ( that what i was checked in first place)
well that is strange, this is the url django-rest-framework.org and I can locate this paragraph: If you're intending to use the browsable API you'll probably also want to add REST framework's login and logout views. Add the following to your root urls.py file. urlpatterns = patterns('', ... url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) )
Well, its main page not my link. And its just example of url, not something that coded into framework, so it can by anything.
0

It was caused by me employing a custom auth backend:

# settings.py
AUTHENTICATION_BACKENDS = (
    'web.auth_backends.EmailAuthBackend',
)

# auth_backends.py
class EmailAuthBackend(object):
    def authenticate(self, email=None, password=None):
        try:
            user = User.objects.get(email__iexact=email)
            if user.check_password(password):
                return user
        except User.DoesNotExist:
            return None

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

Basically it was being passed a keyword "username" but it accepted "email" instead. So it raised an exception that was catched in django's contrib.auth.authentificate and user was not able to log in. I solved it by substituting "email" for "username".

1 Comment

Remember to mark this as answer if you found a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.