一个非常简单的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第三方库


热门话题
关于如何将spring mvc重构为普通servlet或jetty处理程序的java建议   java循环和处理数据输入错误   使用java获取更改内容   java试图向一个数组中添加5张不同的“卡”,但它正在添加5张相同的卡   Java函数在Matlab类中变得未定义   多线程Java使用对象作为监视器,那个对象不是太重了吗?   将MySQL日期转换为Java日期:Android   java ResourceBundle在哪里。getBundle(“ResourceFile”,新语言环境(“us”,“us”))查找该文件?   java第一人称摄影机卷   如何在java中交替使用两个字符   addActionListener上下文中的java“this”   几天后,java Grails和Jasig CAS重定向循环   JavaAnt如何在javac中使用exclude、excludesfile?   java如何设置单行RecyclerView上的文本?