2024-05-09 15:29:45 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
#set -x
|
2024-05-09 16:22:18 -05:00
|
|
|
|
|
|
|
|
mkdir -p temp
|
|
|
|
|
|
2024-05-09 15:29:45 -05:00
|
|
|
curl -s -X POST https://api.schwabapi.com/v1/oauth/token \
|
|
|
|
|
-H "Authorization: Basic $(<appCredentials.dat)" \
|
|
|
|
|
-H 'Content-Type: application/x-www-form-urlencoded' \
|
|
|
|
|
-d "grant_type=refresh_token&refresh_token=$(<refresh_token.dat)" > temp/accessTokenReqResp.$$.json
|
|
|
|
|
jq -e -r .access_token temp/accessTokenReqResp.$$.json > access_token.dat
|
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
|
curl -d "" -X POST "https://deadswitch.kawomi.com/api/v1?topic=trade.schwab.error.getNewAccessToken&secs=1&email=joe@kawomi.com"
|
2024-08-27 12:16:01 -05:00
|
|
|
throw "ERROR: GETTING THE ACCESS TOKEN FAILED! $(<temp/accessTokenReqResp.$$.json)" err
|
2024-05-09 15:29:45 -05:00
|
|
|
fi
|
|
|
|
|
#echo Access Token: $(<access_token.dat)
|
2024-05-27 11:23:20 -05:00
|
|
|
|
2024-08-26 15:18:24 -05:00
|
|
|
## I found the refresh token to be empty after the network is unreachable, therefore I don't handle the refresh token here...
|
|
|
|
|
## I have not seen it change, but let's see if they give us a new one before expiry...
|
|
|
|
|
## after all they send it so we should probably process it.
|
|
|
|
|
#jq -e -r .refresh_token temp/accessTokenReqResp.$$.json > temp/refresh_token.dat
|
|
|
|
|
#if [[ $? -eq 0 ]]; then
|
|
|
|
|
# mv temp/refresh_token.dat refresh_token.dat
|
|
|
|
|
#fi
|
|
|
|
|
##echo Refresh Token: $(<refresh_token.dat)
|
|
|
|
|
#
|