nfarina / homebridge-tesla

Tesla plugin for homebridge: https://github.com/nfarina/homebridge
154 stars 38 forks source link

TeslaJS error: Unauthorized #60

Closed focher closed 3 years ago

focher commented 3 years ago

I recently started receiving the following and the plugin is no longer working.

[1/31/2021, 6:24:11 PM] [Model 3] Logging into Tesla with username/password…
[1/31/2021, 6:24:12 PM] [Model 3] Got a login token.
TeslaJS error: Unauthorized

It seems this is actually related to a change in the way Tesla is allowing authentication, and the TeslaJS library is not updated to support it. I've also created an issue in that repository (https://github.com/mseminatore/TeslaJS/issues/218).

focher commented 3 years ago

It appears there's a pull request that is working to add support for the new authentication flow - and add support for MFA. Hopefully that will come soon but not sure if some changes will be necessary in the plugin settings to support MFA.

lassenygard commented 3 years ago

The same issue with fixes is found here: timdorr/tesla-api#263

focher commented 3 years ago

https://github.com/mseminatore/TeslaJS/issues/218 has had the PR merged which supports the new Tesla authentication flow and MFA.

focher commented 3 years ago

Just an update. TeslaJS version 4.9.7 has the new login flow. I can report it "works", meaning it solves the Unauthorized error, but there's still an underlying issue in that the authentication is not clean. I have not enabled MFA on my account to test yet.

It does generate a series of errors when attempting to authenticate and retrieve a token, but eventually tries enough times to get the token.

[2/6/2021, 3:38:32 PM] [Model 3] Logging into Tesla with username/password… TeslaJS error: TypeError: Cannot read property 'forEach' of null at /homebridge/node_modules/homebridge-tesla/node_modules/teslajs/src/auth.js:51:26 at tryCallOne (/homebridge/node_modules/homebridge-tesla/node_modules/teslajs/node_modules/promise/lib/core.js:37:12) at /homebridge/node_modules/homebridge-tesla/node_modules/teslajs/node_modules/promise/lib/core.js:123:15 at flush (/homebridge/node_modules/homebridge-tesla/node_modules/teslajs/node_modules/asap/raw.js:50:29) at processTicksAndRejections (internal/process/task_queues.js:75:11)

I think it's worthwhile to update to TeslaJS 4.9.7 even as they continue to work out the underlying loop problem, as it allows the authentication to work with the new official Tesla authentication flow.

focher commented 3 years ago

For those who want to test or simply put a "hotfix" in place for the authentication issue until the package is updated, you can manually open up the Terminal in Homebridge, then navigate to node_modules/homebridge-tesla. Open the package.json in an editor, then change the teslajs entry to ^4.9.7. Save the file and then do an npm upgrade to update TeslaJS to 4.9.7 with the new authentication support.

focher commented 3 years ago

Solved with v2.5.4 that upgraded to use the current TeslaJS library.