sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.3k stars 935 forks source link

got.get hangs when calling Tesla auth API #2039

Open cnshenj opened 2 years ago

cnshenj commented 2 years ago

Describe the bug

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

miraries commented 2 years ago

@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'
    }
});