如何从 Django Rest Framework JWT 令牌中获取用户名 [英] How to get username from Django Rest Framework JWT token

查看:31
本文介绍了如何从 Django Rest Framework JWT 令牌中获取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Django Rest Framework,并且包含一个名为 REST 框架 JWT 身份验证.当您将用户名/密码发送到某个路由时,它会返回一个令牌.然后需要令牌来获得某些路由的权限.但是,如何从令牌中获取用户名?我已经查看了所有包文档并通过了 StackOverflow.它是一个 JSON Web Token,我假设有一个类似 username = decode_token(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.

推荐答案

基本上你可以这样做

username = request.user.username

这篇关于如何从 Django Rest Framework JWT 令牌中获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆