Files
OptionRecorderSchwab/getNewRefreshToken.sh

33 lines
1.2 KiB
Bash
Raw Permalink Normal View History

2024-05-09 15:29:45 -05:00
#!/bin/bash
#set -x
2024-08-27 12:16:01 -05:00
. helpers.sh
mkdir -p temp
echo Set Dyn-IP
2024-05-09 15:29:45 -05:00
myIP=$(ip a | grep 'inet.*192.168.10' | awk -F "[ /]*" '{print $3}')
curl -s "https://ddns.kawomi.com/?domain=cstradebotcallback&address=${myIP}"
echo Get latest certificate
ssh root@192.168.10.2 'cd /etc/letsencrypt/live/current && cat privkey.pem cert.pem' > cert.pem
2024-05-09 15:29:45 -05:00
echo
echo OPEN URL: "https://api.schwabapi.com/v1/oauth/authorize?client_id=$(<appKey.dat)&redirect_uri=https://cstradebotcallback.ddns.kawomi.com:2222/"
2024-05-09 15:29:45 -05:00
echo
#theCode=$(sudo ./codeReceiveServer.py)
theCode=$(./codeReceiveServer.py)
2024-05-09 15:29:45 -05:00
echo Code is $theCode
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=authorization_code&code=${theCode}&redirect_uri=https://cstradebotcallback.ddns.kawomi.com:2222/" > temp/refreshTokenReqResp.$$.json
jq -e -r .refresh_token temp/refreshTokenReqResp.$$.json > temp/refresh_token.$$.dat
if [[ $? -eq 0 ]]; then
2024-08-27 12:16:01 -05:00
log "New Refresh Token created." info
cp temp/refresh_token.$$.dat refresh_token.dat
else
2024-08-27 12:16:01 -05:00
throw "Error getting new refresh token _$(<temp/refresh_token.$$.dat)_" err 1
fi
2024-05-09 15:29:45 -05:00
echo Refresh Token: $(<refresh_token.dat)