Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get username from Django Rest Framework JWT token

I am using Django Rest Framework and i've included a 3rd party package called REST framework JWT Auth. It returns a token when you send a username/password to a certain route. Then the token is needed for permission to certain routes. However, how do I get the username from the token? I've looked all through the package documentation and went through StackOverflow. It is a JSON Web Token and I am assuming there is a method like username = decode_token(token) but I haven't found such a method.

like image 372
Gary Holiday Avatar asked Oct 03 '16 01:10

Gary Holiday


People also ask

What is JWT in Django REST framework?

Simple JWT provides a JSON Web Token authentication backend for the Django REST Framework. It aims to cover the most common use cases of JWTs by offering a conservative set of default features. It also aims to be easily extensible in case a desired feature is not present.


1 Answers

Basically you could do this

username = request.user.username
like image 77
Sardorbek Imomaliev Avatar answered Sep 23 '22 17:09

Sardorbek Imomaliev