Created
October 25, 2024 22:38
-
-
Save johnsimcall/4d534d5ee261966e6904c99938ed93ef to your computer and use it in GitHub Desktop.
Decode JWT in bash (OpenShift authentication tokens)
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
# 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