Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TeslaJS error: Unauthorized #218

Closed
focher opened this issue Feb 1, 2021 · 10 comments
Closed

TeslaJS error: Unauthorized #218

focher opened this issue Feb 1, 2021 · 10 comments

Comments

@focher
Copy link

focher commented Feb 1, 2021

I am seeing this in the Homebridge plugin that utilizes TeslaJS (where I also created a bug report), but I believe the underlying problem is related to the changes Tesla has been making to the authentication process to properly support MFA and OAUTH2. As the Homebridge plugin uses TeslaJS, it appears that the error is coming from within this library.

According to https://tesla-api.timdorr.com/api-basics/authentication, Tesla has deprecated the /oauth/token endpoint.

[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
@focher
Copy link
Author

focher commented Feb 1, 2021

I notice there's a pull request with code to handle the new login flow and that you're working on it with the submitter. Just leaving this issue open until that's implemented.

@mseminatore
Copy link
Owner

@focher I've merged the PR from @DoctorMcKay which migrates to the new auth.

@mseminatore
Copy link
Owner

@focher @DoctorMcKay today the new auth flow is failing. It appears that the hidden form fields are missing. Anyone else seeing the same?

@edlea
Copy link
Contributor

edlea commented Feb 3, 2021

@focher @DoctorMcKay today the new auth flow is failing. It appears that the hidden form fields are missing. Anyone else seeing the same?

Yes, I've experience the same. I was about to work up a PR to retry the first HTML GET request a couple of times as that mostly mitigates the issue for now.

@DoctorMcKay
Copy link
Contributor

I just updated my own app to use the new auth flow via the latest version of TeslaJS and it worked fine for me, so it does seem like there's some intermittent issue there and that retries are probably the best way to deal with it.

@wga22
Copy link

wga22 commented Feb 5, 2021

I have an automated script, and retries are not ideal. I suppose I could put a loop in the code, to retry 10 times or something...

@mseminatore
Copy link
Owner

I've found, as others have said, that the WAF throttles you and returns another page if you call too frequently. As I am testing my Tesla Control app, which unfortunately cannot use TeslaJS, I've encountered these issues. Waiting a few hours seems to correct. I sure wish the delay were shorter while I am still debugging.

@wga22 I would not recommend frequent retries. I've heard that Tesla servers will freeze your account if they believe you may be a DDoS attack. That requires a password reset to correct.

@benthehorn
Copy link

As mentioned above, I think you are missing the code for getting the actual refresh token. It’s described here https://tesla-api.timdorr.com/.

@mseminatore
Copy link
Owner

@benthehorn Yes, refresh token is not yet supported but the new auth flow is in place.

@mseminatore
Copy link
Owner

Tesla is placing a shell game with their WAF. Auth was broken but with the latest PR is now working again. I am closing this issue. A user has contributed a PR for refresh tokens. I'll look at that and merge if it looks good. If refresh is not fixed we can open a new issue to track that work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants