curl: Authenticate to API using NETOSECRET
Shell script that takes a NETOSECRET API key, builds a JWT request token, authenticates to the Fusion API, and output the bearer token to use in subsequent API calls.
1
2
🔐 Load NETOSECRET Environment Variable
# Step 2: Retrieve and validate NETOSECRET
if [ -z "$NETOSECRET" ]; then
echo "❌ Environment variable NETOSECRET is not set."
echo "To retrieve this value from the Fusion Portal, see:"
echo "https://docs.netography.com/reference/create-a-netography-api-key"
exit 1
fi
netosecret=$NETOSECRET3
📦 Decode and Extract Secret Fields
# Step 3: Decode the secret and extract fields using jq
decoded=$(echo "$netosecret" | base64 -d)
appname=$(echo "$decoded" | jq -r .appname)
appkey=$(echo "$decoded" | jq -r .appkey)
shortname=$(echo "$decoded" | jq -r .shortname)
sharedsecret=$(echo "$decoded" | jq -r .sharedsecret)
url=$(echo "$decoded" | jq -r .url)4
🏗️ Construct JWT Header and Payload
# Step 4: Create JWT header and payload
header='{"alg":"HS256","typ":"JWT"}'
iat=$(date +%s)
jti=$((RANDOM * RANDOM))
payload=$(jq -nc \
--arg appname "$appname" \
--arg appkey "$appkey" \
--arg shortname "$shortname" \
--argjson iat "$iat" \
--argjson jti "$jti" \
'{iat:$iat,jti:$jti,appname:$appname,appkey:$appkey,shortname:$shortname}')5
6
7
8
9
Last updated