Auto Renew Access Token

mabene 4 years ago updated by James 4 years ago 6

Currently the site seems to store just the access token returned from tesla API, and send manual renewal requests for when they expire.

The token returned by the apc actually contains a mechanism that seems to allow automatic renewal:in addition to the access_token, you get a refresh_token.

Calling the /oauth/token endpoint with parameters
{ "grant_type", "refresh_token" },
{ "client_id", TESLA_CLIENT_ID },
{ "client_secret", TESLA_CLIENT_SECRET },
{ "refresh_token", <refresh token from previous request>}
seems to work and provides a new access token and a new refresh token.

This should allow automatic token renewal while still not storing tesla account passwords.


All set.

I set things to renew 10 days before expiration of the token.  This way I can still follow the 7 day and 1 day email warnings that come just in case it doesn't auto renew for some reason.  I also setup an email warning for the auto renew to alert you if it didn't work when trying to refresh....just in case.


Thanks a lot for making this happen!

If possible, I'd like to see one more change on the front end side: currently there's no way to input the refresh token when adding the token manually (instead of providing Tesla password to request the token through teslafi). Could you please add an input field to allow manually adding the refresh token?

Finaly, a question about the time the tokens are renewed: is it actually 30 days after creation of the token or 5 days before expiry? Tesla already changed the token lifetime once from 90(?) to 45 days, they might do so again; renewing at 5 days before expiry should be more forgiving of changes by Tesla.


Thanks.  That works perfectly!

I still need to finish the coding on some of the backend but everything is in place on the front end.  When you generate a new token it will give you the option for automatically refreshing the token.  When the token is 30 days old TeslaFi will use the refresh token to obtain a new token and a new refresh token.


Also, consider not showing the access token in plaintext on the settings page.  Once i submit that, there is no need to have that information shown.  You can unlock my car with that info!