I’m trying to get OAuth2 to work with a third party API.
export async function send_code(query) {
let keys = Object.keys(query);
if (keys.includes("code")) {
let url = "";
let client_id = "";
let client_secret = "";
let code = query["code"];
let grant_type = "";
let fullUrl = url + "?client_id=" + client_id + "&client_secret=" + client_secret +
"&code=" + code + "&grant_type=" + grant_type;
let result = fetch(fullUrl, {method: "POST", cache:"reload"}).then(
response => response.json()
);
// ... handle access token
}
// ... handle failure
}
The result I get is always:
{resource:"AuthorizationCode",field:"",code:"expired"}
With Postman everything works flawlessly.
Could it be that fetch sends multiple requests. Since after sending the first the code is expired.
And if so how can I solve this?