一个非常简单的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何时可以运行。toString()是否有可能返回重复的字符串?   使用REST进行Java应用程序登录验证?   java测试onErrorResume()Spring Webflux   java设置一个单元格样式,使数字显示为百分比ApachePOI   java仅替换regex az09   java将字符串附加到文件   java Hibernate:如何在集合中查找对象   当独立客户端为Web服务实例化代理时,java WebSphere会生成ClassNotFoundException   java简单算法。我做不好   java我的代码有什么问题?我想用Android制作一个“cardflip”动画   java如何模拟Springbean及其自动连接的参数?   java在Android中将arraylist对象的某些参数显示到列表视图中   java setOnclickListener(此)错误   java自动连接未按类型连接bean   java如何禁止在Viewpager上滑动?   java代码检查每个if语句吗?   java NIO选择器OP_READ和OP_WRITE,关于处理它们的一些问题   java如何在不锁定文件的情况下获取文件大小   Oculus Rift的Java API?   java是一种选择。仍然需要fork来设置bootClasspath