Improve cloud.refresh() to auto-scale expiry based on token validity
The cloud.refresh() API helper seems to work great in keeping up a functional token. What really needs to be done though is to create some logic into cloud.authenticate() to "every now and then" refresh() as well.
Since we don't actually know the expiry logic of the tokens it's a bit of a guesswork though what criteria to use for refresh automation. i.e. does a token expire if it isn't used for X amount of time? Or does a token expire even if it's actively used after X amount of time?
A naive implementation could simply refresh the token once a day which is totally overkill but better than refreshing say once a week and finding it expired and having to trigger the OTP flow.
Summa summarum, needs thinking about, feedback welcome.
The structural changes part of the remote milestone need to get out of the way before I can fully consider this.
The tokens are JWT tokens so I was able to decode the header parameters. Based on those token expiry is 28 days.
With v0.2.9 cloud.ping() now also checks for refresh with a 24h cooldown. It's still totally overkill but negligible extra load.
I'm still leaving this open since we could read the JWT tokens for their expiry and do a "buffered expiry" .. i.e. allow the refresh automation when it's less than 5 days to expiry. (Of course overridable.)