← Lessons/Anatomy of a JWT
← Anatomy of a JWT

Is it still valid?

Learn

Is it still valid?

exp is a NumericDate, so checking it is plain integer arithmetic: compare it with the current time in the same unit. date +%s prints the current Unix time in seconds.

now=$(date +%s)
if (( now >= exp )); then echo "expired"; fi

This token was issued for a short window that's long gone, which is normal: access tokens usually live minutes to an hour, so a stolen one stops working soon. A real API does exactly this check on every request, before it trusts a single claim.

Compare the token's exp with the current Unix time. Print token expired if the expiry has passed, otherwise token still valid.

$ bash solution.sh
Loading...

Output

Run your solution to see its output here.