0
0
IOT Protocolsdevops~10 mins

Token-based authentication (JWT) in IOT Protocols - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to decode a JWT token using a secret key.

IOT Protocols
decoded = jwt.decode(token, [1], algorithms=["HS256"])
Drag options to blanks, or click blank then click option'
Apublic_key
Bauth_key
Ctoken_key
Dsecret_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using a public key instead of the secret key.
Using the token itself as the key.
2fill in blank
medium

Complete the code to create a JWT token with a payload and secret.

IOT Protocols
token = jwt.encode({"user_id": 123}, [1], algorithm="HS256")
Drag options to blanks, or click blank then click option'
Apublic_key
Bjwt_token
Csecret_key
Dauth_token
Attempts:
3 left
💡 Hint
Common Mistakes
Using a public key or token variable instead of the secret key.
3fill in blank
hard

Fix the error in the code to verify the JWT token expiration.

IOT Protocols
payload = jwt.decode(token, secret, algorithms=["HS256"], options=[1])
Drag options to blanks, or click blank then click option'
A{"verify_exp": True}
B{"verify_exp": False}
C{"check_exp": True}
D{"validate_exp": False}
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect option keys or disabling expiration verification.
4fill in blank
hard

Fill both blanks to create a JWT token with an expiration time of 1 hour.

IOT Protocols
payload = {"user": "iot_device", "exp": datetime.datetime.utcnow() [1] datetime.timedelta([2]=1)}
token = jwt.encode(payload, secret, algorithm="HS256")
Drag options to blanks, or click blank then click option'
A+
B-
Chours
Dminutes
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+', or using 'minutes' instead of 'hours'.
5fill in blank
hard

Fill all three blanks to extract the user ID from a decoded JWT payload safely.

IOT Protocols
user_id = payload.get([1], [2]) if payload and payload.get([3]) else None
Drag options to blanks, or click blank then click option'
A"user_id"
BNone
D"id"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys or not providing a default value.