from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
# 第一个参数是一个密钥, 第二个参数过期时间
s = Serializer("hard to guess", expires_in=3600)
# 为指定的数据生成一个加密签名
token = s.dumps({"confirm": 3})
print(token)
# 解码令牌, 参数为令牌字符串
data = s.loads(token)
print(data)
结果:
b'eyJpYXQiOjE1OTE1MzIxODgsImFsZyI6IkhTNTEyIiwiZXhwIjoxNTkxNTM1Nzg4fQ.eyJjb25maXJtIjozfQ.qu61kzvLJGBSRcx-FN26LRpkBSSK3xcWsGBzJAP6m6idv3C2wKBSJ69Y-vRrJVuhuNwW7TCxMa19k0IIcD4CkQ'
{'confirm': 3}