Validate and get the user using the jwt token inside a view

458 views
Skip to first unread message

Robin Lery

unread,
Sep 14, 2017, 11:12:40 PM9/14/17
to django...@googlegroups.com
I am using django-rest-framework for the REST API and django-rest-framework-jwt for JSON web token authentication. After a successful login, the user is provided with a token. I have found how to verify a token with the api call, but is there any way to validate the token inside a view and get the user of that token, similar to request.user?

oon arfiandwi

unread,
Sep 15, 2017, 1:09:50 PM9/15/17
to django...@googlegroups.com

Hi,

have you try to use jwt_decode_handler(token)?
I found this on utils.py

I check the source code of verify token,
there's reference to decode handler inside the code.

-- 
sincerely,
Oon Arfiandwi


On Fri, Sep 15, 2017 at 10:11 AM, Robin Lery <robi...@gmail.com> wrote:
I am using django-rest-framework for the REST API and django-rest-framework-jwt for JSON web token authentication. After a successful login, the user is provided with a token. I have found how to verify a token with the api call, but is there any way to validate the token inside a view and get the user of that token, similar to request.user?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B4-nGopatOzbDz4HZmZwPOTVpv5whYBpW-%3DgPdG%2BFhDcmUJsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Robin Lery

unread,
Sep 16, 2017, 12:05:29 AM9/16/17
to django...@googlegroups.com
Thanks. But that doesn't verify the token.

Robin Lery

unread,
Sep 16, 2017, 4:25:42 AM9/16/17
to django...@googlegroups.com
I was about to that by this

from rest_framework_jwt.serializers import VerifyJSONWebTokenSerializer

data = {'token': token}
valid_data = VerifyJSONWebTokenSerializer().validate(data)
user = valid_data['user']

Hope this helps any body like me.
Reply all
Reply to author
Forward
0 new messages