Last active
May 23, 2020 13:46
-
-
Save qrkourier/ab5bb279047b640b8ff82c9dd9730b5c to your computer and use it in GitHub Desktop.
source this file to make NETFOUNDRY_API_TOKEN available to child processes
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
# source this file in bash or zsh to make | |
# NETFOUNDRY_API_TOKEN | |
# available to processes run in the same shell | |
_get_nf_token(){ | |
[[ $# -eq 2 ]] || { | |
echo "ERROR: send two params: client_id client_secret" >&2 | |
return 1 | |
} | |
client_id=$1 | |
client_secret=$2 | |
access_token=$( | |
http POST https://netfoundry-production.auth0.com/oauth/token \ | |
"content-type: application/json" \ | |
"client_id=${client_id}" \ | |
"client_secret=${client_secret}" \ | |
"audience=https://gateway.production.netfoundry.io/" \ | |
"grant_type=client_credentials" | \ | |
jq -r .access_token | |
) | |
echo ${access_token} | |
} | |
[[ ! -z ${CLIENT_ID:-} && ! -z ${CLIENT_SECRET:-} ]] && { | |
export NETFOUNDRY_API_TOKEN=$(_get_nf_token ${CLIENT_ID} ${CLIENT_SECRET}) | |
} || { | |
echo "ERROR: failed to export NETFOUNDRY_API_TOKEN. "\ | |
"Are permanent credential vars CLIENT_ID, CLIENT_SECRET assigned?" >&2 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment