如何解码令牌并获取Django的djangorestframew

如何解码令牌并获取Django的djangorestframew

本文介绍了如何解码令牌并获取Django的djangorestframework-jwt软件包的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我已经开始使用djangorestframework-jwt软件包而不是PyJWT,我只是不知道如何解码传入的令牌(我知道有验证令牌方法)....我需要知道的是如何对令牌进行解码并取回已编码的信息……

I have started using djangorestframework-jwt package instead of PyJWT , I just could not know how to decode the incoming token (I know there is verify token methode).... All I need to know is how to decode the token and get back info encoded......

推荐答案

可能为时已晚,但我们可以解码jwt并取回有效载荷使用来自jwt模块的jwt.decode

May be its too late to answer, but we can decode jwt and get our payload backusing jwt.decode from jwt module

假设您获得的jwt令牌看起来像并且加密的有效载荷位于令牌的中间

Assume that jwt token you get looks like and your encrypted payload lies in middle of the token

{
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwib3JpZ19pYXQiOjE1MzIxMzg3ODQsImV4cCI6MTUzMjEzOTA4NCwidXNlcl9pZCI6MSwiZW1haWwiOiJwcmF0aWsucHVjc2RAZ21haWwuY29tIiwibXlmIjoxfQ.enG5qiSOPh98YYZBpScHSL5TM8RBz6JhU6uF0l1bZXM"
}

以下是解决方案的摘要:

Following is snippet for solution:

import jwt
#jwt.decode(<encoded token>,<secret key>,<algorthm>)
decodedPayload = jwt.decode('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwib3JpZ19pYXQiOjE1MzIxMzg3ODQsImV4cCI6MTUzMjEzOTA4NCwidXNlcl9pZCI6MSwiZW1haWwiOiJwcmF0aWsucHVjc2RAZ21haWwuY29tIiwibXlmIjoxfQ.enG5qiSOPh98YYZBpScHSL5TM8RBz6JhU6uF0l1bZXM',None,None)

这篇关于如何解码令牌并获取Django的djangorestframework-jwt软件包的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:36