Skip to content

Instantly share code, notes, and snippets.

@jfsanchez91
Last active June 8, 2022 20:25
Show Gist options
  • Save jfsanchez91/3948b293107d841360f1027d8d2377ee to your computer and use it in GitHub Desktop.
Save jfsanchez91/3948b293107d841360f1027d8d2377ee to your computer and use it in GitHub Desktop.
# JWT decoder
# How to use:
# token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
# 1 - echo $token | jwtd
# 2 - jwtd $token
# # output:
# # {
# # "alg": "HS256",
# # "typ": "JWT",
# # "sub": "1234567890",
# # "name": "John Doe",
# # "iat": 1516239022
# # }
value=${*:-`cat -`}
header=$(jq -R 'split(".") | .[0] | @base64d | fromjson' <<< "$value")
payload=$(jq -R 'split(".") | .[1] | @base64d | fromjson' <<< "$value")
echo "$header $payload" | jq -s add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment