help with my api and JWT

83 views
Skip to first unread message

ola neat

unread,
Jul 25, 2020, 3:52:38 PM7/25/20
to django...@googlegroups.com
hey guy i got an issue implementing jwt in my drf project, i've got it installed and when the user signs up or login the token get generated but when i use the same token to test other end point i get
i've got my code and response attached
{
"detail": "Authentication credentials were not provided."
}
Screenshot from 2020-07-25 20-42-51.png
Screenshot from 2020-07-25 20-43-20.png
Screenshot from 2020-07-25 20-46-18.png
Screenshot from 2020-07-25 20-45-27.png

Robson Andrade

unread,
Jul 25, 2020, 5:46:04 PM7/25/20
to Django users
Hello friend,

I noticed that you are using the standard token authentication system. However, this method does not correspond to JWT.

Since you want to use authentication through JWT with DRF, you must use:

1) A JWT library that implements this type of authentication which helps you to create a login route to obtain the access token, route to the refresh token, or other routes and resources you need. I can recommend you: Simple JWT (my favorite) https://github.com/SimpleJWT/django-rest-framework-simplejwt or REST framework JWT Auth - https://jpadilla.github.io/django-rest-framework-jwt /

2) Next, you must correctly configure these Django modules.

3) When everything is properly configured, you must first obtain the access token and refresh token through a previously created user login.

4) Once you have the access token, you must send it to the request head as follows, for example:
 {Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTU5NTYwMzIyNSwianRpIjoiY2QxYTRiYWJiZTgzNDVhMjlkMGJmYTIzNTc0Zjk0ZjEiLCJ1c2VyX2lkIjo4fQ.i6bmtiqFyWyxo7mMuZxQjN9RvM-DjaiOwRVxeRBdiwM"}

5) Every 5 minutes you must request a new access token through the refresh token, but now in the body of the request:
 { "Refresh", "ppADdAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTU5NTYwMzIyNSwianRpIjoiY2QxYTRiYWJiZTgzNDVhMjlkMGJmYTIzNTc0Zjk0ZjEiLCJ1c2VyX2lkIjo4fQ.i6bmtiqFyWyxo7mMuZxQjN9RvM-DjaiOwRVxeRBccdSA"}


Hope this helps!

See you later!

ola neat

unread,
Jul 26, 2020, 10:47:40 AM7/26/20
to django...@googlegroups.com
thanks it worked

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/069d7c8c-3aba-457c-ba7c-b047779a5f29o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages