Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Generate V3 Refresh Token for API Authentication

MrTemple

Member
Jul 16, 2020
111
196
Pacific North Wilderness
Tesla has changed how they do authentication (referred to now as v3). Every app and site that uses the API has to be updated.

And if you don't want to give apps/sites your Tesla.com credentials (which you shouldn't, no matter how much you trust them, because they can always be hacked with a harvester), then you need to generate a special token the apps/sites can use to talk to the Tesla scripting API.

This is like a 'valet key' for the scripting interface, giving the 3rd party very limited access to just the features they need.

Here's a working PHP script to locally generate your V3 Refresh Token.

**Working** PHP to Generate Refresh Token (Steps 1-4) · Discussion #288 · timdorr/tesla-api

Confirmed to work with TeslaFI.com (which has already been updated to support the new authentication).
 

Ostrichsak

Active Member
Sep 6, 2018
3,524
3,564
Colorado, USA
Tesla has changed how they do authentication (referred to now as v3). Every app and site that uses the API has to be updated.

And if you don't want to give apps/sites your Tesla.com credentials (which you shouldn't, no matter how much you trust them, because they can always be hacked with a harvester), then you need to generate a special token the apps/sites can use to talk to the Tesla scripting API.

This is like a 'valet key' for the scripting interface, giving the 3rd party very limited access to just the features they need.

Here's a working PHP script to locally generate your V3 Refresh Token.

**Working** PHP to Generate Refresh Token (Steps 1-4) · Discussion #288 · timdorr/tesla-api

Confirmed to work with TeslaFI.com (which has already been updated to support the new authentication).
Thanks for doing this. Very useful for those who wish to use 3rd party apps w/o surrendering their login and password.
 
Nov 8, 2020
16
14
Genève
Hello,

It's unfortunately not working anymore...

array(2) {
["response"]=>
string(17) "invalid_sso_token"
["refresh_token"]=>
NULL
}

Does anybody know how to generate a Token on MAC with a similar method or could the script be updated ?
Thanks,
Fly
 

tjbonzo

Member
May 5, 2018
8
8
Chicago
Hello,

It's unfortunately not working anymore...

array(2) {
["response"]=>
string(17) "invalid_sso_token"
["refresh_token"]=>
NULL
}

Does anybody know how to generate a Token on MAC with a similar method or could the script be updated ?
Thanks,
Fly
Getting (mostly) the same message (along with some notices).

$ php /home/bob/bin/tesla.php PHP Notice: Undefined offset: 1 in /home/bob/bin/tesla.php on line 323 PHP Notice: Trying to access array offset on value of type null in /home/bob/bin/tesla.php on line 350 PHP Notice: Trying to access array offset on value of type null in /home/bob/bin/tesla.php on line 351 PHP Notice: Undefined index: access_token in /home/bob/bin/tesla.php on line 375 array(2) { ["response"]=> string(17) "invalid_sso_token" ["refresh_token"]=> NULL } 323: $code= explode('&',explode('https://auth.tesla.com/void/callback?code=',$apiResult)[1])[0]; 350: $BearerToken = $apiResultJson['access_token']; 351: $RefreshToken = $apiResultJson['refresh_token']; 375: $this->accessToken = $apiResultJson['access_token'];
 

Spectra207

Member
Apr 7, 2021
16
17
Ottawa, Canada
I'm looking to generate my own token to avoid providing credentials to any third-party and I've seen mention in this thread and elsewhere of the Auth app for iOS. What makes that app any more trustworthy than the third-party app you're ultimately generating the token for? Looking to understand this better.
Thanks
 
  • Like
Reactions: coolname

About Us

Formed in 2006, Tesla Motors Club (TMC) was the first independent online Tesla community. Today it remains the largest and most dynamic community of Tesla enthusiasts. Learn more.

Do you value your experience at TMC? Consider becoming a Supporting Member of Tesla Motors Club. As a thank you for your contribution, you'll get nearly no ads in the Community and Groups sections. Additional perks are available depending on the level of contribution. Please visit the Account Upgrades page for more details.


SUPPORT TMC
Top