Below is the function I had implemented:
I have successfully developed a code that fulfills all my requirements.
async function obtainBearerToken(parameters) {
var applicationID = parameters.applicationID;
var applicationSecret = parameters.applicationSecret;
var requestHeaders = new Headers();
requestHeaders.append("Authorization", "Basic " + btoa(applicationID + ":" + applicationSecret));
var requestOptions = {
method: 'GET',
headers: requestHeaders,
credentials:'omit' //use this to prevent browser-popup requesting basic auth credentials.
};
return fetch("<url-here>", requestOptions)
.then(response => response.json())
.then(result => {
return result;
})
.catch(error => { console.log(error); return false; });
}
result = await obtainBearerToken({applicationID:"<app-id>", applicationSecret:"<app-secret>"});
I designed it in such a way that you can directly inspect it in the console immediately!
I hope this solution resolves your issue if you encountered a similar problem as I did!