[英]How can I verify jwt using "djangorestframework-simplejwt"
I am beginner in drf (Django rest framework), and now I'm making authorization logic with JWT.我是 drf(Django rest 框架)的初学者,现在我正在使用 JWT 制作授权逻辑。 I heard that djangorestframework-simplejwt is most famous library in drf.
我听说 djangorestframework-simplejwt 是 drf 中最著名的库。
I saw docs, but there are no way to verify token.我看到了文档,但没有办法验证令牌。 (exactly i cannot find it :( )
(正是我找不到它:()
thank you.谢谢你。
in JWT you can verify if a token is valid by decoding it, your key = any key used during token creation, your algorithm = algorithm used during token creation, token = value of the token to decode在 JWT 中,您可以通过解码来验证令牌是否有效,您的密钥 = 令牌创建期间使用的任何密钥,您的算法 = 令牌创建期间使用的算法,令牌 = 要解码的令牌的值
import jwt
decoded_result = jwt.decode(<token>, key=<your key>, algorithms=<your algorithm>)
print(decoded_result)
this prints decoded payload from your token if valid, else raises jwt exceptions which can be caught in a try-catch block for further processing.如果有效,这将从您的令牌中打印解码的有效负载,否则会引发 jwt 异常,这些异常可以在 try-catch 块中捕获以进行进一步处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.