Library for decoding JWT material
This library decodes JWT material
- b64_padding()
- b64_tr()
- json_kv()
- google_pubkey()
- google_verify()
- jwt_header_json()
- jwt_payload_json()
- jwt_display()
Parses a base64 padded JWT string
$ source functions/jwt-decode.sh
$ b64_padding 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjEyMzQ1Njc4OTBhYmNkZWYwMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1NjciLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiYXpwIjoiMTIzNDU2Nzg5MDEyLTEyMzQ1Njc4OTBhYmNkZWZnaGlqa2xtbm9wcXJzdHV2dy5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF1ZCI6IjEyMzQ1Njc4OTAxMi0xMjM0NTY3ODkwYWJjZGVmZ2hpamtsbW5vcHFyc3R1dncuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMjM0NTY3ODkwMTIzNDU2Nzg5MDEiLCJlbWFpbCI6Im1vY2tAZ29vZ2xlLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdF9oYXNoIjoiMTIzNDU2Nzg5MGFiYy1ERUZHSElKS0wiLCJpYXQiOjE2MTczNDIzNjMsImV4cCI6MTYxNzM0NTk2MywianRpIjoiMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1Njc4OTBhYmNkZWYxMjM0NTY3OCJ9.WQiOiJodHRwczovL3ZhdWx0L215LXJvbGUiLCJhenAiOiJtb2NrQGZvMKPhz_iiY9eWIs_YNn3Ix1Uil4u2_3Ix1Uil4_2OHFjThJeFfGGU8xRz8qw5kCYfd5J7Kuy4Of_mHMekDQcE3qut3fsxzd_o58VuiiY9_WIs1YNn3Ix1Uil4u2OHFjThJeFfGGU8xRz8emCRJzI9Bhqgxrd1A3ZoFRi9_ho6n7raVq-NJW33xZFbmiKpJDX1huD1zrBemCRJzI9Bhqgxrd1A3ZoFRi9pho6n7raVq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CI6IjEyMzQ1Njc4OTBhYmNkZWYwMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1NjciLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiYXpwIjoiMTIzNDU2Nzg5MDEyLTEyMzQ1Njc4OTBhYmNkZWZnaGlqa2xtbm9wcXJzdHV2dy5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF1ZCI6IjEyMzQ1Njc4OTAxMi0xMjM0NTY3ODkwYWJjZGVmZ2hpamtsbW5vcHFyc3R1dncuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMjM0NTY3ODkwMTIzNDU2Nzg5MDEiLCJlbWFpbCI6Im1vY2tAZ29vZ2xlLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdF9oYXNoIjoiMTIzNDU2Nzg5MGFiYy1ERUZHSElKS0wiLCJpYXQiOjE2MTczNDIzNjMsImV4cCI6MTYxNzM0NTk2MywianRpIjoiMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1Njc4OTBhYmNkZWYxMjM0NTY3OCJ9.WQiOiJodHRwczovL3ZhdWx0L215LXJvbGUiLCJhenAiOiJtb2NrQGZvMKPhz/iiY9eWIs/YNn3Ix1Uil4u2/3Ix1Uil4/2OHFjThJeFfGGU8xRz8qw5kCYfd5J7Kuy4Of/mHMekDQcE3qut3fsxzd/o58VuiiY9/WIs1YNn3Ix1Uil4u2OHFjThJeFfGGU8xRz8emCRJzI9Bhqgxrd1A3ZoFRi9/ho6n7raVq+NJW33xZFbmiKpJDX1huD1zrBemCRJzI9Bhqgxrd1A3ZoFRi9pho6n7raVqC+NJW33xZFbmiKpJDX/1huD1zrBcRKwzjfS73gmJc/y5ehiJQHWNthO
- $1 (string): base64 encoded string
- base64 encoded string replacing '-_' with '+/'
Parses JSON string and returns value of key requested
$ source functions/jwt-decode.sh
$ json_kv '{"alg":"RS256","kid":"1234567890abcdef01234567890abcdef1234567","typ":"JWT"}' alg
RS256
- $1 (string): JSON string
- $2 (string): key
- value of key searched for, or 'null' if not found
Google OAuth2 public key signature fetch
$ source functions/jwt-decode.sh
$ google_pubkey '13e8d45a43cb2242154c7f4dafac2933fea20374'
/path/to/tmp.signature.file
- $1 (string): key id (kid)
- File containing public key material
Google OAuth2 veriification of JWT header + payload (i.e. body) with signature
$ source functions/jwt-decode.sh
$ google_verify 'eyJhbGciOiJSUzI1NiIsI....gmJc_y5ehiJQHWNthO'
Verified OK
- $1 (string): JWT material
- Message indicating success or failure of JWT verification
Parses JWT material and returns decoded JWT header
$ source functions/jwt-decode.sh
$ jwt_header_json 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjEyMzQ1Njc4OTBhYmNkZWYwMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1NjciLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiYXpwIjoiMTIzNDU2Nzg5MDEyLTEyMzQ1Njc4OTBhYmNkZWZnaGlqa2xtbm9wcXJzdHV2dy5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF1ZCI6IjEyMzQ1Njc4OTAxMi0xMjM0NTY3ODkwYWJjZGVmZ2hpamtsbW5vcHFyc3R1dncuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMjM0NTY3ODkwMTIzNDU2Nzg5MDEiLCJlbWFpbCI6Im1vY2tAZ29vZ2xlLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdF9oYXNoIjoiMTIzNDU2Nzg5MGFiYy1ERUZHSElKS0wiLCJpYXQiOjE2MTczNDIzNjMsImV4cCI6MTYxNzM0NTk2MywianRpIjoiMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1Njc4OTBhYmNkZWYxMjM0NTY3OCJ9.WQiOiJodHRwczovL3ZhdWx0L215LXJvbGUiLCJhenAiOiJtb2NrQGZvMKPhz_iiY9eWIs_YNn3Ix1Uil4u2_3Ix1Uil4_2OHFjThJeFfGGU8xRz8qw5kCYfd5J7Kuy4Of_mHMekDQcE3qut3fsxzd_o58VuiiY9_WIs1YNn3Ix1Uil4u2OHFjThJeFfGGU8xRz8emCRJzI9Bhqgxrd1A3ZoFRi9_ho6n7raVq-NJW33xZFbmiKpJDX1huD1zrBemCRJzI9Bhqgxrd1A3ZoFRi9pho6n7raVqC-NJW33xZFbmiKpJDX_1huD1zrBcRKwzjfS73gmJc_y5ehiJQHWNthO'
{"alg":"RS256","kid":"1234567890abcdef01234567890abcdef1234567","typ":"JWT"}
- $1 (string): JWT material
- base64 decoded JWT header
Parses JWT material and returns decoded JWT payload
$ source functions/jwt-decode.sh
$ jwt_payload_json 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjEyMzQ1Njc4OTBhYmNkZWYwMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1NjciLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiYXpwIjoiMTIzNDU2Nzg5MDEyLTEyMzQ1Njc4OTBhYmNkZWZnaGlqa2xtbm9wcXJzdHV2dy5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF1ZCI6IjEyMzQ1Njc4OTAxMi0xMjM0NTY3ODkwYWJjZGVmZ2hpamtsbW5vcHFyc3R1dncuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMjM0NTY3ODkwMTIzNDU2Nzg5MDEiLCJlbWFpbCI6Im1vY2tAZ29vZ2xlLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdF9oYXNoIjoiMTIzNDU2Nzg5MGFiYy1ERUZHSElKS0wiLCJpYXQiOjE2MTczNDIzNjMsImV4cCI6MTYxNzM0NTk2MywianRpIjoiMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1Njc4OTBhYmNkZWYxMjM0NTY3OCJ9.WQiOiJodHRwczovL3ZhdWx0L215LXJvbGUiLCJhenAiOiJtb2NrQGZvMKPhz_iiY9eWIs_YNn3Ix1Uil4u2_3Ix1Uil4_2OHFjThJeFfGGU8xRz8qw5kCYfd5J7Kuy4Of_mHMekDQcE3qut3fsxzd_o58VuiiY9_WIs1YNn3Ix1Uil4u2OHFjThJeFfGGU8xRz8emCRJzI9Bhqgxrd1A3ZoFRi9_ho6n7raVq-NJW33xZFbmiKpJDX1huD1zrBemCRJzI9Bhqgxrd1A3ZoFRi9pho6n7raVqC-NJW33xZFbmiKpJDX_1huD1zrBcRKwzjfS73gmJc_y5ehiJQHWNthO'
{"iss":"accounts.google.com","azp":"123456789012-1234567890abcdefghijklmnopqrstuvw.apps.googleusercontent.com","aud":"123456789012-1234567890abcdefghijklmnopqrstuvw.apps.googleusercontent.com","sub":"123456789012345678901","email":"[email protected]","email_verified":true,"at_hash":"1234567890abc-DEFGHIJKL","iat":1617342363,"exp":1617345963,"jti":"1234567890abcdef1234567890abcdef12345678"}
- $1 (string): JWT material
- base64 decoded JWT payload
Parses JWT material and returns environment variables
$ functions/jwt-decode.sh 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjEyMzQ1Njc4OTBhYmNkZWYwMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1NjciLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiYXpwIjoiMTIzNDU2Nzg5MDEyLTEyMzQ1Njc4OTBhYmNkZWZnaGlqa2xtbm9wcXJzdHV2dy5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF1ZCI6IjEyMzQ1Njc4OTAxMi0xMjM0NTY3ODkwYWJjZGVmZ2hpamtsbW5vcHFyc3R1dncuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMjM0NTY3ODkwMTIzNDU2Nzg5MDEiLCJlbWFpbCI6Im1vY2tAZ29vZ2xlLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdF9oYXNoIjoiMTIzNDU2Nzg5MGFiYy1ERUZHSElKS0wiLCJpYXQiOjE2MTczNDIzNjMsImV4cCI6MTYxNzM0NTk2MywianRpIjoiMTIzNDU2Nzg5MGFiY2RlZjEyMzQ1Njc4OTBhYmNkZWYxMjM0NTY3OCJ9.WQiOiJodHRwczovL3ZhdWx0L215LXJvbGUiLCJhenAiOiJtb2NrQGZvMKPhz_iiY9eWIs_YNn3Ix1Uil4u2_3Ix1Uil4_2OHFjThJeFfGGU8xRz8qw5kCYfd5J7Kuy4Of_mHMekDQcE3qut3fsxzd_o58VuiiY9_WIs1YNn3Ix1Uil4u2OHFjThJeFfGGU8xRz8emCRJzI9Bhqgxrd1A3ZoFRi9_ho6n7raVq-NJW33xZFbmiKpJDX1huD1zrBemCRJzI9Bhqgxrd1A3ZoFRi9pho6n7raVqC-NJW33xZFbmiKpJDX_1huD1zrBcRKwzjfS73gmJc_y5ehiJQHWNthO'
export JWT_HEADER='{"alg":"RS256","kid":"1234567890abcdef01234567890abcdef1234567","typ":"JWT"}'
export JWT_ALGORITHM=RS256
...
- $1 (string): JWT material
- Environment variable export commands for JWT materal components