got icon indicating copy to clipboard operation
got copied to clipboard

got.get hangs when calling Tesla auth API

Open cnshenj opened this issue 2 years ago • 1 comments

Describe the bug

  • Node.js version: 16.14.0
  • OS & version: Windows 11 Version 10.0.22000.652

Actual behavior

got hangs when calling Tesla auth API: GET https://auth.tesla.com/oauth2/v3/authorize

await got.get("https://auth.tesla.com/oauth2/v3/authorize", { retry: { limit: 0 } });

node-fetch properly returns data (Bad Request when no query parameters are provided):

await fetch("https://auth.tesla.com/oauth2/v3/authorize");

...

Expected behavior

...

Code to reproduce

...

Checklist

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got.

cnshenj avatar May 09 '22 08:05 cnshenj

@cnshenj Looks like the tesla api timeouts on purpose due to got's default user-agent. Probably related to following

Avoid setting a User-Agent header that looks like a browser (such as Chrome or Safari). The SSO service has protections in place that will require executing JavaScript if a browser-like user agent is detected.

from https://tesla-api.timdorr.com/api-basics/authentication#step-1-obtain-the-login-page

For example this works for me

const response = await got.get("https://auth.tesla.com/oauth2/v3/authorize", {
    headers: {
        'user-agent': 'no urls'
    }
});

miraries avatar May 20 '22 09:05 miraries