一个非常简单的jwt库

simplejwt的Python项目详细描述


简单重量

PyPI versionBuild StatusTest CoverageMaintainability

一个非常简单的jwt库。

支持的算法

  • HS256
  • HS384
  • HS512

用法

编码

返回新令牌。

from simplejwt import encode
token = encode('secret', {'my_payload': 'some_data'}, 'HS256')
# eyJ0eXBlIjogIkpXVCIsICJhbGciOiAiSFMyNTYifQ.eyJteV9wYXlsb2FkIjogInNvbWVfZGF0YSJ9.BXAs5tYkARpGHhegb8g8bfj8KhjFUTTjdEf81Ma1VhY
NameTypeDefaultDescription
^{}^{}N/AThe secret used to create the token.
^{}^{}N/AThe payload data contained within the token.
^{}^{}^{}The algorithm to use to create the token.

制造

返回新令牌。此函数具有在rfc7519中指定的已注册声明的参数。

有效负载中提供的任何已注册声明将优先于作为参数提供的任何声明。

from simplejwt import make
token = make('secret', {'my_payload': 'some_data'}, 'HS256', issuer='acme', valid_to=1234567)
# eyJ0eXBlIjogIkpXVCIsICJhbGciOiAiSFMyNTYifQ.eyJteV9wYXlsb2FkIjogInNvbWVfZGF0YSIsICJpc3MiOiAiYWNtZSIsICJleHAiOiAxMjM0NTY3fQ.Nr5IADzsOhlzjxnghquBrRwewg10srDHu__-HN7GGGA
NameTypeDefaultDescription
^{}^{}N/AThe secret used to create the token.
^{}^{}N/AThe payload data contained within the token.
^{}^{}^{}The algorithm to use to create the token.
^{}^{}^{}The issuer of the token.
^{}^{}^{}The subject of the token.
^{}^{}^{}The audience of the token.
^{}^{}^{}The expiry date of the token as a timestamp.
^{}^{}^{}The date the token is valid from as a timestamp.
^{}^{}^{}The date the token was issued as a timestamp.
^{}^{}^{}The id of the token.

解码

从令牌返回有效负载。

from simplejwt import encode, decode
token = encode('secret', {'my_payload': 'some_data'}, 'HS256')
payload = decode('secret', token, 'HS256')
# {'my_payload': 'some_data'}
NameTypeDefaultDescription
^{}^{}N/AThe secret used to decode the token.
^{}^{}N/AThe token to decode.
^{}^{}^{}The algorithm to use to create the token.

运行测试

使用测试依赖项安装软件包

pip install -e ".[test]"

运行tox

tox

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java绘制两个重叠图像   java如何将图像放入源文件夹并在Eclipse中使用   java性能调优:com。麦克亨格。v2。资源库。Basicresourcepool。waitAvailable()方法占用应用程序的大部分运行时间   当分数的平行值为某个数字或更高时,java将传递的元素设置为true?   无法在java中使用SimpleFileVisitor删除某些文件。尼奥。文件   java从KType中检索注释   hadoop设置作业。java代码中的属性文件来启动oozie操作   java无响应jbutton请求并发性   java停止当前线程,直到调用的线程完成,然后继续它   JList的java大小调整问题?   通过web浏览器运行java小程序时引发异常   java如何处理selenium webdriver自动化上的背靠背警报   java处理函数只会冻结程序   截击中getparams中的java开关盒   用于显示的java getter   java如何在将布局更改为不可见时修复ClassNotFoundException