Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Last active April 1, 2025 09:39
Show Gist options
  • Select an option

  • Save Ajnasz/fe28b3e51c39be042f040934f6d4efae to your computer and use it in GitHub Desktop.

Select an option

Save Ajnasz/fe28b3e51c39be042f040934f6d4efae to your computer and use it in GitHub Desktop.
jwt decode shell script
#!/bin/sh
# Decode JWT token
# Usage: echo <jwt_token> | jwtdecode
# requires jq and coreutils
while read -r input;do
echo "$input" | cut -d . -f 1,2 | tr '.' '\n' | \
while read -r str;do
echo "$str" | basenc -d --base64url | jq .
done
done
@Ajnasz
Copy link
Copy Markdown
Author

Ajnasz commented Mar 13, 2025

AFAIK the base64 variant used in JWT is base64url which is supported by coreutils basenc(1). So you can replace echo "$str"==== | fold -w 4 | sed '$ d' | tr -d '\n' | base64 --decode | jq with echo "$sr" | basenc -d --base64url | jq.

Nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment