Hey All,
Running into an issue, I assume it’s simple, but I’m blanking as to what I am doing wrong.
#!/bin/zsh --no-rcs
client_id="REMOVED"
client_secret="REMOVED"
url="https://REMOVED"
##Gets Access Token
getAccessToken() {
response=$(curl --silent --location --request POST "${url}/api/oauth/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=${client_id}" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_secret=${client_secret}")
access_token=$(echo "$response" | plutil -extract access_token raw -)
token_expires_in=$(echo "$response" | plutil -extract expires_in raw -)
token_expiration_epoch=$(($current_epoch + $token_expires_in - 1))
}
checkTokenExpiration() {
current_epoch=$(date +%s)
if > token_expiration_epoch -ge current_epoch ]]
then
echo "Token valid until the following epoch time: " "$token_expiration_epoch"
else
echo "No valid token available, getting new token"
getAccessToken
fi
}
# I run the function here, and it provides me the access token and timer of '59'
getAccessToken
echo $access_token
echo $token_expires_in
echo $token_expiration_epoch
# I then run the function to check on expiration, and it tells me no valid token
checkTokenExpiration
# I recreates the token gives me 59 again.
echo $token_expires_in
Results:
access token info removed (But it does show the full access token
59
58
No valid token available, getting new token
59
Anyone able to tell what I’m missing?