27.01.2022, 13:02
problem found, grant_type incorrect transfered
And next? do i need to refresh some tokens?
Code:
function GetToken()
body = json.encode({
grant_type = 'refresh_token',
client_id = 'ownerapi',
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
}
})
if not res or code ~= 200 then
return
end
resp = table.concat(resp)
resp = json.pdecode(resp)
bearer_token = resp.access_token
--refresh_token = resp.refresh_token
return bearer_token
end
And next? do i need to refresh some tokens?