Trying to generate a JWT token using the PyJWT library.
When I use the below program to generate the JWT token - the token does not work.
However when I use the website https://jwt.io/ with the same details - the token works. Is there something that I'm missing.
I need python generate the token properly so I can automate some API's that need this token.
Python program:
import jwt
import base64
code = jwt.encode({'sub':'String','nbf':'1501594247',
'exp':'1501767047', 'iss': 'string', 'aud': 'String'},
base64.b64encode('secret'), algorithm='HS256')
print code
Example:
code = jwt.encode({'sub':'AccountNUmber.QTVR','nbf':'1501594247','exp':'1501860089', 'iss': 'client_id', 'aud': 'https://login.google.com/oauth'},
base64.b64encode('secret'), algorithm='HS256')
Result:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjbGllbnRfaWQiLCJhdWQiOiJodHRwczovL2xvZ2luLmdvb2dsZS5jb20vb2F1dGgiLCJzdWIiOiJBY2NvdW50TlVtYmVyLlFUVlIiLCJleHAiOiIxNTAxODYwMDg5IiwibmJmIjoiMTUwMTU5NDI0NyJ9.dRUUQYJ-RmxgoExwPyrvHPzX9SsxcpX1rOWlhisxNsg
Token generated by https://jwt.io/ :
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjbGllbnRfaWQiLCJhdWQiOiJodHRwczovL2xvZ2luLmdvb2dsZS5jb20vb2F1dGgiLCJzdWIiOiJBY2NvdW50TlVtYmVyLlFUVlIiLCJleHAiOiIxNTAxODYwMDg5IiwibmJmIjoiMTUwMTU5NDI0NyJ9.INp-ZnnL8Uj7MIwLYmpZtGyTyZG-oqZRNW8iZ145jVs
The token generated by https://jwt.io/ works when I call the endpoint. And I get a status code 200 (Success).
However when I use the token generated from my program it gives 'Invalid Token' - 400 (Bad Request).
