Created
May 21, 2024 15:10
-
-
Save joonas/e02d9d1411089c56b436d936b02e700d to your computer and use it in GitHub Desktop.
Zero dependency (bash doesn't count) JWT decoding command-line utility
This file contains hidden or 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
#!/bin/bash | |
# pad base64URL encoded to base64 | |
paddit() { | |
input=$1 | |
l=`echo -n $input | wc -c` | |
while [ `expr $l % 4` -ne 0 ] | |
do | |
input="${input}=" | |
l=`echo -n $input | wc -c` | |
done | |
echo $input | |
} | |
# read and split the token and do some base64URL translation | |
read jwt | |
read h p s <<< $(echo $jwt | tr [-_] [+/] | sed 's/\./ /g') | |
h=`paddit $h` | |
p=`paddit $p` | |
# assuming we have jq installed | |
echo "header:" | |
echo $h | base64 -d | jq | |
echo "payload:" | |
echo $p | base64 -d | jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment