简体   繁体   English

如何使用“djangorestframework-simplejwt”验证 jwt

[英]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.

相关问题 注册后我如何获得 jwt 令牌(djangorestframework) - How can i after registration get jwt tokens (djangorestframework) Python 微服务如何在 Authorization 标头中使用 JWT 验证请求? - How can a Python Microservice verify requests using a JWT in an Authorization header? 我如何过滤 Json 响应,仅使用 Djangorestframework 中的 DateFilter 将 Year 参数传递给 DateTime 字段 - how can i filter the Json response by only passing the Year parameter to the DateTime field using DateFilter in Djangorestframework 无法验证 JWT - Can't verify JWT DjangoRestFramework - 如何使用“pk”过滤列表? - DjangoRestFramework - How can I use 'pk' to filter a list? 使用djangorestframework-jwt get_jwt_token视图时是否需要创建一个简单的登录视图? - Is any needs to create a simple login view when using djangorestframework-jwt obtain_jwt_token views? 如何使用python PyJWT和公共PEM证书验证JWT? - How to verify a JWT using python PyJWT with a public PEM cert? 如何使用带有公钥的python PyJWT验证JWT - How to verify a JWT using python PyJWT with public key 如何使用 DRF 制作 API 以接受和验证 JWT? - How to make an API using DRF to accept and verify a JWT? 在 Django(drf 和 simplejwt)中究竟应该如何实现基于 JWT 的身份验证? - How exactly should JWT-based authentication be implemented in Django (drf and simplejwt)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM