1

I am trying to configure token authentcation on django-rest-framework. I have added the appropriate settings, and set

'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.TokenAuthentication',
)

and the authentication works perfectly from the browser client or curl.

However if I try to use the browseable API, I get 401 unauthorized errors. The login page is available, but just doesn't actually seem to log me in. If I add session authentication:

'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.TokenAuthentication',
    'rest_framework.authentication.SessionAuthentication',
)

the browseable API works, but token requests fail with Unauthorised errors. Does anyone have a solution to this?

1 Answer 1

1

You need to pass the Token in the header of each request:

The token key should be included in the Authorization HTTP header. The key should be prefixed by the string literal "Token". For ex:

Authorization: Token 4564b09199c62bcf94fgds46dd0e4bbdfc6ee4b
Sign up to request clarification or add additional context in comments.

1 Comment

And how do you pass the token in each request @Anush?

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.