alandtse / tesla

Tesla custom integration for Home Assistant. This requires a refresh token be generated by third-party apps to login.
Apache License 2.0
588 stars 100 forks source link

Car Issue: #921

Closed sgriessini closed 6 months ago

sgriessini commented 6 months ago

Is there an existing issue for this?

Version of the Tesla component

3.20.4

Version of the Tesla car software

2024.2.7

Model

Model Y

Current Behavior

I have an authentication issue. I've removed the integration due to the (re-)authentication problem and added it again. After the adding process (using proxy, adding refresh token) the integration says "success". But no car is added and the integration remains in "could not authenticate" error.

Expected Behavior

I expect that the car in my tesla account is added to HA as device with all his entities.

Debug logs

2024-03-22 11:18:08.452 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in -19805 days, 12:41:52
2024-03-22 11:18:08.452 DEBUG (MainThread) [teslajsonpy.connection] Oauth expiration detected
2024-03-22 11:18:08.452 DEBUG (MainThread) [teslajsonpy.connection] Refreshing access token with refresh_token
2024-03-22 11:18:08.756 DEBUG (MainThread) [teslajsonpy.connection] Unable to refresh sso oauth token
2024-03-22 11:18:08.756 DEBUG (MainThread) [teslajsonpy.connection] Auth returned {'error': 'login_required', 'error_description': 'Login required', 'referenceID': 'c217a33d-f0ee-4eec-9681-02f8527186a5-1711102688648'}
2024-03-22 11:18:08.757 WARNING (MainThread) [homeassistant.config_entries] Config entry 'sgriessini@xxx.de' for tesla_custom integration could not authenticate

Anything else?

No response

llamafilm commented 6 months ago

This is happening to a lot of people while using the reauthentication config flow; there's a bug where it seems to reuse the same refresh token twice, which is no longer allowed. The workaround is to delete the car and add it back again. But you said you've already done that, so I don't know what the issue is.

sgriessini commented 6 months ago

To be clear here, with "to delete the car" you mean the integration in HA?

llamafilm commented 6 months ago

A few days ago I made a major change to the proxy addon. Now it no longer generates refresh tokens. Please update, then delete this integration and add it back, and use Tesla Auth app to generate the refresh token, and let us know if this is still an issue.

sgriessini commented 6 months ago

I removed the addon today and reinstalled it again. Configured it point to point. Removed the tesla integration and added the car again, using the refresh token (from Chrome Tesla Token addon). Configuration ended without an error, but the integration still remains in "could not authenticate". Adding the car without the proxy works without any issues, so I assume the fault in the proxy, but there is no error logged (enabled debug mode).

sgriessini commented 6 months ago

Here's some more debug info from the integration:

2024-03-30 10:48:25.708 DEBUG (MainThread) [custom_components.tesla_custom.config_flow] Running in supervised environment
2024-03-30 10:48:25.842 DEBUG (MainThread) [custom_components.tesla_custom.config_flow] Found addon: c03d64a7_tesla_http_proxy
2024-03-30 10:48:50.135 DEBUG (MainThread) [custom_components.tesla_custom.config_flow] Credentials successfully connected to the Tesla API
2024-03-30 10:48:50.137 DEBUG (MainThread) [custom_components.tesla_custom] <ssl.SSLContext object at 0x7fa6ad0f6050>
2024-03-30 10:48:50.178 DEBUG (MainThread) [teslajsonpy.controller] 552 endpoints loaded
2024-03-30 10:48:50.179 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in -19813 days, 13:11:10
2024-03-30 10:48:50.179 DEBUG (MainThread) [teslajsonpy.connection] Oauth expiration detected
2024-03-30 10:48:50.179 DEBUG (MainThread) [teslajsonpy.connection] Refreshing access token with refresh_token
2024-03-30 10:48:51.406 DEBUG (MainThread) [teslajsonpy.connection] Received bad auth response: 
2024-03-30 10:48:51.407 DEBUG (MainThread) [teslajsonpy.connection] Unable to refresh sso oauth token
2024-03-30 10:48:52.880 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in -19813 days, 13:11:08
2024-03-30 10:48:52.880 DEBUG (MainThread) [teslajsonpy.connection] Oauth expiration detected
2024-03-30 10:48:52.880 DEBUG (MainThread) [teslajsonpy.connection] Refreshing access token with refresh_token
2024-03-30 10:48:54.895 DEBUG (MainThread) [teslajsonpy.connection] Received bad auth response: 
2024-03-30 10:48:54.895 DEBUG (MainThread) [teslajsonpy.connection] Unable to refresh sso oauth token
2024-03-30 10:48:57.829 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in -19813 days, 13:11:03
2024-03-30 10:48:57.829 DEBUG (MainThread) [teslajsonpy.connection] Oauth expiration detected
2024-03-30 10:48:57.830 DEBUG (MainThread) [teslajsonpy.connection] Refreshing access token with refresh_token
2024-03-30 10:48:58.664 DEBUG (MainThread) [teslajsonpy.connection] Received bad auth response: 
2024-03-30 10:48:58.664 DEBUG (MainThread) [teslajsonpy.connection] Unable to refresh sso oauth token
2024-03-30 10:49:02.850 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in -19813 days, 13:10:58
2024-03-30 10:49:02.850 DEBUG (MainThread) [teslajsonpy.connection] Oauth expiration detected
2024-03-30 10:49:02.850 DEBUG (MainThread) [teslajsonpy.connection] Refreshing access token with refresh_token
2024-03-30 10:49:04.260 DEBUG (MainThread) [teslajsonpy.connection] Received bad auth response: 
2024-03-30 10:49:04.260 DEBUG (MainThread) [teslajsonpy.connection] Unable to refresh sso oauth token
2024-03-30 10:49:05.180 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in -19813 days, 13:10:55
2024-03-30 10:49:05.180 DEBUG (MainThread) [teslajsonpy.connection] Oauth expiration detected
2024-03-30 10:49:05.180 DEBUG (MainThread) [teslajsonpy.connection] Refreshing access token with refresh_token
2024-03-30 10:49:06.181 DEBUG (MainThread) [teslajsonpy.connection] Received bad auth response: 
2024-03-30 10:49:06.181 DEBUG (MainThread) [teslajsonpy.connection] Unable to refresh sso oauth token
2024-03-30 10:49:06.182 WARNING (MainThread) [homeassistant.config_entries] Config entry 'myemail@gmx.de' for tesla_custom integration could not authenticate
llamafilm commented 6 months ago

In debug mode, the proxy should log every incoming HTTP request, like this:

Received GET request for /api/1/products 2024-03-29T21:23:48-07:00 [debug]

If you don’t see that, then I guess the request is getting lost on its way to the addon somehow.

Which chrome app are you using to make the token? It needs to support Fleet API.

sgriessini commented 6 months ago

Which chrome app are you using to make the token? It needs to support Fleet API.

I'm using Access Token Generator for Tesla: https://chromewebstore.google.com/search/Access%20Token%20Generator%20for%20Tesla

It generates a Refresh token, Access token, ID token, ...

llamafilm commented 6 months ago

The source code for that app shows it's using the old Owner API, that will not work here.

If you don't have a Mac or iOS device to run the app I linked above, the best alternative I've seen is the Python script someone shared here: https://github.com/llamafilm/tesla-http-proxy-addon/discussions/69

sgriessini commented 6 months ago

Hi Elliott,

this is it :-) The refresh token from the app (I used the iPhone from my son) did the job. Thanks a lot, I didn't imagine that the tesla tokens are so different.