Created
November 2, 2022 14:02
-
-
Save veggiemonk/f5ac775f720c384728709d2de038cc62 to your computer and use it in GitHub Desktop.
JWT with jq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extract jwt token info | |
function jwtd () { | |
if [[ -x $(command -v jq) ]]; then | |
jq -R 'split(".") | .[0],.[1] | @base64d | fromjson' <<< "${1}" | |
echo "{\"Signature\": \"$(echo "${1}" | awk -F'.' '{print $3}')\"}" | |
fi | |
} | |
# Show the experiation date | |
# NOTE: on a mac, it needs coreutils for the date (use with `gdate`) | |
# -> brew install coreutils | |
function jwtexp () { | |
res=$(jwtd "${1}" | jq '.exp | select( . != null )' | xargs -I {} gdate -d "@{}") | |
echo "expire at: ${res}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment