Skip to content

Instantly share code, notes, and snippets.

@veggiemonk
Created November 2, 2022 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veggiemonk/f5ac775f720c384728709d2de038cc62 to your computer and use it in GitHub Desktop.
Save veggiemonk/f5ac775f720c384728709d2de038cc62 to your computer and use it in GitHub Desktop.
JWT with jq
# 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