Skip to content
C

JWT Creation and Expiry Check

Mediumpython

Create two JWTs for the same user_id — one that expires an hour from now, and one that (deliberately) already expired an hour ago — then decode both and report the result.

Note: rather than literally creating a short-lived token and sleeping past its expiry (which would add a real, judge-timeout-risking delay to every run), this problem builds the "already expired" case directly by setting its exp claim in the past — testing the exact same jwt.decode()/ExpiredSignatureError behavior instantly and deterministically.

Approach: encode a validtoken (exp = now + 1 hour) and an expiredtoken (exp = now - 1 hour) for the given user_id, decode each in its own try/except, and print the outcome of both.

Input: One line: an integer user_id.

Output: Two lines: "Valid token decoded: user_id=<id>" and "Expired token: correctly rejected as expired".

Input (stdin)

Output

Run your code to see output here...