[Django]-Django Rest Framework Postman Token Authentication

46👍

You are setting the header to Authorization: Token when it really should just be Authorization. The header is actually just Authorization, but the value is Token [token_string], where [token_string] is the authorization token that you have obtained.

3👍

enter image description hereFor the new version of postman it is necessary to choose Auth 2 type authentication in the left panel, then in the right panel, specify the DRf key which is "Token" and in the value the token itself.

0👍

In addition to the above answer, make sure to enable "Follow Authorization header" under setting (See below screenshot)
enter image description here

0👍

After Specifying Authorization and Token value try to add the token in an environment so that every time you don’t have to copy the token value.

0👍

After get access token from http://127.0.0.1:8000/accounts/login/

such this :

{
    "email": "user@example.com",
    "tokens": {
        "refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTY2NjI2NTAxMSwiaWF0IjoxNjY2MTc4NjExLCJqdGkiOiJjZWM3MzJmNDZkMGE0MTNjOTE3ODM5ZGYxNzRiNzMxZCIsInVzZXJfaWQiOjcwfQ.5Rd25s6msp72IHyU1BxE4ym24YIEbhyFsBdUztGXz0I",
        "access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjY2MjY1MDExLCJpYXQiOjE2NjYxNzg2MTEsImp0aSI6IjgyOWFmZGE5MWY2ODRhNDZhMDllZGMzMmI0NmY0Mzg5IiwidXNlcl9pZCI6NzB9.TYhi0INai293ljc5zBk59Hwet-m9a1Mc1CtA56BEE_8"
    },
    "id": 70
}

copy content of "access" key in response, then in post man in Headers add new item by key : Authorization and value such this:

Bearer eyJ0eXAi....

that eyJ0eXAi…. is value of access key.

enter image description here

then send the request.

👤Amirio

Leave a comment