I'm new using the JWT on web-apps. I'm not sure what info should be stored in a JWT, but in my case, I'm saving sensitive user data, such as e-mail and username. I wish to safely secure this info on my JWT.
Using the pyjwt
module, I was able to successfully create my tokens. Here is an example of how I've been using it.
import jwt
from datetime import datetime, timedelta
data = {
"user": {}, # Here I would fill with my user data.
"exp": datetime.utcnow() + timedelta(hours=2)
}
jwt.encode(data,"my-super-secret-key", "HS256")
This code above, returns a token where I thought it was encrypted.
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7fSwiZXhwIjoxNjMwMzAxMjI4fQ.sF3NeOArV5Mkgz9oemNMA4-RPF-mXKCIkQrlMQPLMV4
Using the https://jwt.io/ JWT checker, I found out that my token was actually being "decrypted" without the use of my-super-secret-key
. This made me wonder what was the purpose of the secret key in PyJWT anyways. My guess is that it's just for signing the token.
And how can I actually secure my JWT token? (I've read about JWE, but didn't quite understood it yet, would really appreciate a concise explanation)