Skip to content

Instantly share code, notes, and snippets.

@seva-ramin
Last active March 25, 2021 15:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seva-ramin/0735c55b4d293f44ff50c18df130ee40 to your computer and use it in GitHub Desktop.
Save seva-ramin/0735c55b4d293f44ff50c18df130ee40 to your computer and use it in GitHub Desktop.
JWT Decoder using bash
#!/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 $h | base64 -d | jq
echo $p | base64 -d | jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment