Skip to content

Instantly share code, notes, and snippets.

@johnsimcall
Created October 25, 2024 22:38
Show Gist options
  • Save johnsimcall/4d534d5ee261966e6904c99938ed93ef to your computer and use it in GitHub Desktop.
Save johnsimcall/4d534d5ee261966e6904c99938ed93ef to your computer and use it in GitHub Desktop.
Decode JWT in bash (OpenShift authentication tokens)
# https://gist.github.com/thomasdarimont/46358bc8167fce059d83a1ebdb92b0e7?permalink_comment_id=5139846#gistcomment-5139846
function jwt_decode(){
jq -R 'split(".") | .[1] | @base64d | fromjson |
# you can replace the "localtime" with "gmttime" if that makes sense
if .exp then (.expStr = (.exp | localtime | strftime("%Y-%m-%dT%H:%M:%S %Z"))) else . end |
if .iat then (.iatStr = (.iat | localtime | strftime("%Y-%m-%dT%H:%M:%S %Z"))) else . end |
if .nbf then (.nbfStr = (.nbf | localtime | strftime("%Y-%m-%dT%H:%M:%S %Z"))) else . end |
.' <<< "$1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment