Telsa Oauth Authentication

675 views
Skip to first unread message

gerard....@gmail.com

unread,
Apr 8, 2021, 9:23:19 PM4/8/21
to Automate

Tesla changed the way they do authentication to use OAuth. It's not just a bunch of GET and POST anymore.


You have to parse HTML that gets returned to scrape data. I'm not sure Automate can do this.

Henrik "The Developer" Lindqvist

unread,
Apr 8, 2021, 9:42:07 PM4/8/21
to Automate
Use the HTTP request block to get the page content, then execute a findAll function on the content to find the "hidden fields", whatever they are.

gerard....@gmail.com

unread,
Apr 9, 2021, 12:45:55 AM4/9/21
to Automate
It's strange. I can get a successful response in SoapUI for the first step, but doing it in Automate results in an error response (400 status code)

Request Method: GET
Request content type: JSON
Request content body: {"client_id": "ownerapi", "code_challenge": "123", "code_challenge_method": "S256", "redirect_uri": "https://auth.tesla.com/void/callback", "response_type": "code", "scope": "openid email offline_access", "state": "123", "login_hint": "X...@yahoo.com"}

I tried adding a user agent string that I found in a Python script that talks to the API, but it made no difference.

Request headers: {"User-Agent": "Mozilla/5.0 (Linux; Android 10; Pixel 3 Build/QQ2A.200305.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/85.0.4183.81 Mobile Safari/537.36"}

Henrik "The Developer" Lindqvist

unread,
Apr 9, 2021, 1:02:34 AM4/9/21
to Automate
GET requests usually don't have a body, try encoding the parameters in the URL, e.g.:
Request URL: https://auth.tesla.com/oauth2/v3/authorize?{{"client_id": "ownerapi", "code_challenge": "123", "code_challenge_method": "S256", "redirect_uri": "https://auth.tesla.com/void/callback", "response_type": "code", "scope": "openid email offline_access", "state": "123", "login_hint": "X...@yahoo.com"};urlEncode}
Request Method: GET

gerard....@gmail.com

unread,
Apr 9, 2021, 2:45:29 PM4/9/21
to Automate
Message has been deleted

Henrik "The Developer" Lindqvist

unread,
Apr 9, 2021, 7:04:30 PM4/9/21
to Automate
Message has been deleted
Message has been deleted

gerard....@gmail.com

unread,
Apr 25, 2021, 9:04:32 AM4/25/21
to Automate

I had gotten the authentication working for a few weeks. I just noticed that it fails with a timeout. Is it possible Tesla is blocking calls from Automate somehow?  That URL works in my browser, but Automate on any platform fails with a java.net.SocketTimeoutException error.

Henrik "The Developer" Lindqvist

unread,
Apr 25, 2021, 10:25:37 PM4/25/21
to Automate
Unlikely, since Automate hasn't even connected yet.
Maybe their site is just overloaded/slow, try setting longer Timeout, default it just 15s.

gerard....@gmail.com

unread,
Apr 26, 2021, 9:35:59 AM4/26/21
to Automate
I tracked it down to the User Agent I was told to use in the header: {"User-Agent": "Mozilla/5.0 (Linux; Android 10; Pixel 3 Build/QQ2A.200305.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/85.0.4183.81 Mobile Safari/537.36"}

If I remove that, it works again. I think Tesla noticed that user agent is being used by scripts and is blocking it.
Reply all
Reply to author
Forward
0 new messages