djangodjango-rest-frameworkdjango-rest-authauth-token

get auth token using dj-rest-auth when user logged in


Previously I was using django-rest-auth package and I was getting the auth token when user log in in response response.data.key and this auth token or key was working fine with the api calls as authentication auth

Previously for django-rest-auth:

"/rest-auth/login/"

was getting the response.data.key as auth token and that was working I have stored in the cookie for later use

.get("/rest-auth/user/", {
     headers: {
       "Content-Type": "application/json",
       Authorization: "Token " + response.data.key + "",
       },
  })

It was working to get info on user and also was working when used in other api calls by setting it in

Authorization: "Token " + response.data.key + ""

But now, I'm using dj-rest-auth package instead of django-rest-auth and shifted my urls to

/dj-rest-auth/login

and I'm not getting any key or auth token that I can use for authorization in header.

.get("/dj-rest-auth/user/", {
     headers: {
       "Content-Type": "application/json",
       Authorization: "Token " + response.data.? + "",
       },
  })

It's not working because now I'm getting access_token , refresh_token and user info. I tried to use access_token and refresh_token for authorization in header but it's not working because I'm not getting key or auth token in response when user log in

Note: django-rest-auth is no more maintained and dj-rest-auth is forked from the previous one and have more functions (this is the reason why I'm switching)

How to get auth token or key by using dj-rest-auth package so that I can use it in the header of API calls for authorization?


Solution

  • Check that you don't have an REST_USE_JWT = True in your settings. That setting will enable JWT authentication scheme instead of a (default) token-based.