Last active
April 30, 2022 00:10
-
-
Save rvanlaar/1dd96cc31739572a1f081374776167ac to your computer and use it in GitHub Desktop.
Get TransIP JWT
This file contains 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 | |
# | |
# Get a TRANSIP JWT to use for authenticated API requests | |
# https://api.transip.nl/rest/docs.html#header-authentication | |
# | |
# necessary commandline tools: | |
# jq | |
# curl | |
# | |
# Setting it up: | |
# save your transip private key as: private.key | |
# Set up the following variables: | |
# "TRANSIP_USER" to your transip username | |
# "EXPIRATION_TIME" defaults to 30 minutes | |
# set sane defaults, i.e. exit on: | |
# -e: non zero exit code, | |
# -u: an undefined variable | |
# pipefile: return exit code of last command in the pipe | |
set -euo pipefail | |
TRANSIP_USER="" | |
EXPIRATION_TIME="30 minutes" | |
nonce=`openssl rand -base64 12` | |
POST_JSON=`jq -n \ | |
--arg user "$TRANSIP_USER" \ | |
--arg nonce "$nonce" \ | |
--arg identifier "curl-token-$nonce" \ | |
--arg expiration "$EXPIRATION_TIME" \ | |
'{ | |
"login": $user, | |
"nonce": $nonce, | |
"read_only": false, | |
"expiration_time": $expiration, | |
"label": $identifier, | |
"global_key": false | |
}'` | |
SIGNATURE=`echo -n "$POST_JSON" | openssl dgst -sha512 -sign private.key|openssl base64 -A` | |
curl -v -X POST \ | |
-H "Content-Type: application/json" \ | |
-H "Signature: $SIGNATURE" \ | |
--data "$POST_JSON" \ | |
"https://api.transip.nl/v6/auth/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment