Files
Learn-Python-Programming-Th…/ch09/jwt/tok.py
T
adii1823 8704175145 ch09
2021-10-28 17:39:56 +05:30

22 lines
500 B
Python

# jwt/tok.py
import jwt
data = {'payload': 'data', 'id': 123456789}
algs = ['HS256', 'HS512']
token = jwt.encode(data, 'secret-key')
data_out = jwt.decode(token, 'secret-key', algorithms=algs)
print(token)
print(data_out)
# decode without verifying the signature
jwt.decode(token, options={'verify_signature': False})
# let's use another algorithm
token512 = jwt.encode(data, 'secret-key', algorithm='HS512')
data_out = jwt.decode(token512, 'secret-key', algorithms=['HS512'])
print(data_out)