Complete the code to decode a JWT token using a secret key.
decoded = jwt.decode(token, [1], algorithms=["HS256"])
The secret key is used to decode the JWT token to verify its authenticity.
Complete the code to create a JWT token with a payload and secret.
token = jwt.encode({"user_id": 123}, [1], algorithm="HS256")The secret key is required to encode the payload into a JWT token securely.
Fix the error in the code to verify the JWT token expiration.
payload = jwt.decode(token, secret, algorithms=["HS256"], options=[1])
Setting 'verify_exp' to True ensures the token expiration is checked during decoding.
Fill both blanks to create a JWT token with an expiration time of 1 hour.
payload = {"user": "iot_device", "exp": datetime.datetime.utcnow() [1] datetime.timedelta([2]=1)}
token = jwt.encode(payload, secret, algorithm="HS256")The expiration time is set by adding 1 hour to the current UTC time.
Fill all three blanks to extract the user ID from a decoded JWT payload safely.
user_id = payload.get([1], [2]) if payload and payload.get([3]) else None
This code safely gets the 'user_id' from the payload or returns None if not present.
