2025-03-18 19:21:17 +01:00

38 lines
873 B
Fish

function jwtd
if test (count $argv) = 0
echo "Usage: jwtd TOKEN" >/dev/stderr
return 1
end
if test -z (command -v jq); or test ! -x (command -v jq)
echo "jq is not installed" >/dev/stderr
return 1
end
echo "# HEADERS"
echo "$argv[1]" | jq -R 'split(".") | .[0] | @base64d | fromjson'
echo ""
set body (echo "$argv[1]" | jq -R 'split(".") | .[1] | @base64d | fromjson')
set timestamp (echo $body | jq -r '.exp')
echo "# BODY"
echo $body | jq
echo ""
if test -n "$timestamp" -a "$timestamp" != null
if test "$timestamp" -lt (date +"%s")
echo -n "EXPIRED at: "
else
echo -n "Expires: "
end
date --date="@$timestamp"
else
echo "NEVER EXPIRES!"
end
echo "$argv[1]" | awk -F. '{print "Signature: " $3}'
end