27.01.2022, 11:10
(27.01.2022, 09:41)admin Wrote: Try adding User-Agent/X-Tesla-User-Agent headers as in previous examples. Also try adding client_secret field to the JSON body. You might also need an additional request to exchange bearer token for access token.
I already tried that, but same 400 deny error
Code:
function GetToken()
body = json.encode({
grant_type = 'authorization_code',
client_id = 'ownerapi',
client_secret = client_secret,
refresh_token = refreshToken,
scope = 'openid email offline_access'
})
resp = {}
res, code, headers = http.request({
url = 'https://auth.tesla.com/oauth2/v3/token',
method = 'POST',
source = ltn12.source.string(body),
sink = ltn12.sink.table(resp),
headers = {
['Content-Type'] = 'application/json',
['Accept'] = 'application/json',
['Content-Length'] = #body,
['User-Agent'] = 'Mozilla/5.0 (Linux; Android 9.0.0; VS985 4G Build/LRX21Y; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/58.0.3029.83 Mobile Safari/537.36',
['X-Tesla-User-Agent'] = 'TeslaApp/3.4.4-350/fad4a582e/android/9.0.0'
}
})
log(res, code, headers)
end