安装
pip install itsdangerous
示例
# -*- coding: utf-8 -*- from itsdangerous import TimedJSONWebSignatureSerializer # jwt auth_s = TimedJSONWebSignatureSerializer(secret_key="secret key", expires_in=6) token = auth_s.dumps({"id": 5, "name": "itsdangerous"}) print(token.decode()) # header.payload.Signature # eyJhbGciOiJIUzUxMiIsImlhdCI6MTYxNjU3ODM3MywiZXhwIjoxNjE2NTc4Mzc5fQ # .eyJpZCI6NSwibmFtZSI6Iml0c2Rhbmdlcm91cyJ9 # .meNUr88zejBv0ufR2fKFKXOSi5kxfT4Dpdu1i2M_3BweX66tTcHZqwFrUXGIn-xv1kdgimwZ7EizNS1Y-37kbQ data = auth_s.loads(token) print(data["name"]) # itsdangerous
参考
python itsdangerous模块的具体使用方法