-
-
Save mihaikelemen/5e842969510f034009f7f9d1d3a4a248 to your computer and use it in GitHub Desktop.
JWT
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
| #! /usr/bin/env bash | |
| # creates a JWT in bash | |
| # Static header fields. | |
| HEADER='{ | |
| "type": "JWT", | |
| "alg": "RS256" | |
| }' | |
| # PAYLOAD=$1 | |
| PAYLOAD='{ | |
| "uuid": "TEST", | |
| "role": "system" | |
| }' | |
| # # Use jq to set the dynamic `iat` and `exp` | |
| # # fields on the payload using the current time. | |
| # # `iat` is set to now, and `exp` is now + 1 second. | |
| # PAYLOAD=$( | |
| # echo "${payload}") | |
| function b64enc() { openssl enc -base64 -A | tr '+/' '-_' | tr -d '='; } | |
| function rs_sign() { openssl dgst -binary -sha256 -sign ./private.pem ; } | |
| JWT_HDR_B64="$(echo -n "$HEADER" | b64enc)" | |
| JWT_PAY_B64="$(echo -n "$PAYLOAD" | b64enc)" | |
| UNSIGNED_JWT="$JWT_HDR_B64.$JWT_PAY_B64" | |
| SIGNATURE=$(echo -n "$UNSIGNED_JWT" | rs_sign | b64enc) | |
| echo "$UNSIGNED_JWT.$SIGNATURE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment