# Fill in your credentials below
# User-Agent is set explicitly so default library agents (e.g. curl) are not rejected by the gateway.
CLIENT_ID="REPLACE-ME"
CLIENT_SECRET="REPLACE-ME"
SCOPE="REPLACE-ME"
# Get access token and copy to clipboard (Mac: pbcopy / Windows: clip.exe)
TOKEN_RESPONSE=$(curl -sS -m 30 -w "\n%{http_code}" -X POST https://id.talenom.com/api/b2b/oauth2/v1.0/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "User-Agent: Easor-API-Client/1.0" \
-d "grant_type=client_credentials&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&scope=$SCOPE")
TOKEN_HTTP_CODE=$(echo "$TOKEN_RESPONSE" | tail -n1)
TOKEN_BODY=$(echo "$TOKEN_RESPONSE" | sed '$d')
if [ "$TOKEN_HTTP_CODE" != "200" ]; then
echo "Token request failed with HTTP $TOKEN_HTTP_CODE"
echo "$TOKEN_BODY"
exit 1
fi
ACCESS_TOKEN=$(echo "$TOKEN_BODY" | jq -r .access_token)
if [ -z "$ACCESS_TOKEN" ] || [ "$ACCESS_TOKEN" = "null" ]; then
echo "Token response did not contain access_token:"
echo "$TOKEN_BODY"
exit 1
fi
echo "Access token: $ACCESS_TOKEN"
if command -v pbcopy >/dev/null 2>&1; then
echo "$ACCESS_TOKEN" | pbcopy
echo "Access token copied to clipboard!"
elif command -v clip.exe >/dev/null 2>&1; then
echo "$ACCESS_TOKEN" | clip.exe
echo "Access token copied to clipboard!"
fi