1
votes

I have these endpoints:

urlpatterns += [
    path('api-token-auth/', obtain_jwt_token),
    path('api-token-verify/', verify_jwt_token),
    path('api-token-refresh/', refresh_jwt_token),
    path('api/', include(router.urls)),
]

For example I have a User on backend, and let's say he wants to login to the system. In login page he must provide his username and password, and login page will use "obtain_jwt_token" endpoint, which will automatically check if that user exists or not. If not, backend will return error message, if that User exists and username & password is correct than backend will return a Token, generated by JWT, and that token will live for let's say 1 hour. But the problem is that backend will not return additional data, it will return only Token itself, but not id of that user or something. And that is the problem.

Am I understanding something wrong ? All I want is for backend to return not only the Token, but also id of that user. Or to decode the Token, and get id of User from it.

1
Thanks a lot sir, you should've been post it like an answer !Madi7
Thasnks Madi, glad that I could help youjps

1 Answers

1
votes

Usually you'll find something like username or ID in the token.

You can easily decode the token on client side, it's just simple JSON format, Base64 encoded. You can check your token on https://jwt.io to see what kind of information is in it.

Check also the RFC for JWT: https://tools.ietf.org/html/rfc7519