Closed cjdshaw closed 3 years ago
Ah, I've worked it out. If you add "refreshTokenNeeded":true to the initial login, you get a refresh token in addition, so
curl https://wap.tplinkcloud.com -X POST -d '{"method":"login","url":"https://wap.tplinkcloud.com","params":{"appType":"Kasa_iOS","cloudPassword":"xxx","cloudUserName":"xxx@xxx.com","terminalUUID":"'$KASAUUID'","refreshTokenNeeded":true}}' -H "Content-Type:application/json"
You can then periodically call
curl https://wap.tplinkcloud.com -X POST -d '{"method":"refreshToken","params":{"appType":"Kasa_iOS","terminalUUID":"'$KASAUUID'","refreshToken":"'$KASAREFRESHTOKEN'"}}' -H "Content-Type:application/json"
and get a new access token each time. Oddly, you don't get a new refresh token, so it remains to be seen whether that will expire at some point
It really galls me having to store my credentials in order to periodically obtain a token. After a bit of poking, there seems to be a method "refreshToken", but whatever I pass it, e.g.
curl "https://wap.tplinkcloud.com/" -X POST -d '{"method":"refreshToken","url":"https://wap.tplinkcloud.com","params":{"appType":"Kasa_iOS","token":"'$KASATOKEN'","terminalUUID":"'$KASAUUID'"}}' -H "Content-Type:application/json"
I get {error_code": -20104, "msg": "Parameter doesn't exist"}
Do you have any guesses on what it needs? How did you get this info for "login"? Note that other methods, like "refresh" or "updateToken" return "The method does not exist or is not available" so "refreshToken" is clearly different