Trying to acces an external API through my react.js application to get a Bearer token. But i'm struggling with the following error:
Access to fetch at 'https://login.bol.com/token?grant_type=client_credentials' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Therefore I'm using the following code:
let url = 'http://login.bol.com/token?grant_type=client_credentials';
let client_id = 'client_id';
let client_secret = 'secret_key';
var basicAuth = 'Basic ' + btoa(client_id + ':' + client_secret);
function fetchToken() {
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': basicAuth
},
})
.then(data => data.json())
}
fetchToken();
All though, when I use postman it works: