jwt_token = TokenGenerator(data={'name': 'sample name'})
print(jwt_token.token)
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoic2FtcGxlIG5hbWUiLCJleHAiOjE2MDI1MTg0NDd9.2cLIO-CGcnqQkJILjO3p9GJOhJsidv6F38zXAZttWaw
token_decode = TokenGenerator(token=jwt_token.token)
if token_decode.is_valid():
print(token_decode.data)
{'name': 'sample name'}
token_encode = TokenGenerator(data={'name': 'sample name'}, timeout='1d 5m 7s', key='secrete_key', algorithms='HS256')
Note: d = day, m = minute, s = second. If any parameter is 0 then just skip that parameter. eg. If day = 0d then the string look like: '5m 7s'.
If you set key and algorithms for each token locally then you need to pass the key and algorithms when you decode the jwt token. Other wise token invalid exception will be raised.
token_decode = TokenGenerator(token=token_encode.token, key='secrete_key', algorithms='HS256')
if token_decode.is_valid():
print(token_decode.data)
{'name': 'sample name'}
jwt_token_generator = {
'TIMEOUT': '60m',
'ALGORITHMS': 'HS256',
'KEY': 'almaBud'
}