I am requesting an authorization code
from the OAuth2
Server in order to authenticate a user with my Microsoft App. For more information, I consulted this document.
This is my attempt to make the call:
function httpGet(){
var theUrl = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id="client_id"&response_type=code&redirect_uri="redirect_uri"&response_mode=query&resource=https%3A%2F%2Fservice.contoso.com%2F&state=12345";
var req = new XMLHttpRequest();
req.open('GET', theUrl, true);
req.onreadystatechange = function() {
if (req.readyState === 4) {
if (req.status >= 200 && req.status < 400) {
console.log(req.responseText)
} else {
console.log("error")
}
}
};
req.send();
}
However, I encountered the following error:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
To try and resolve the issue, I added
req.setRequestHeader("Access-Control-Allow-Origin", "*");
Despite this modification, I still received the following error:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.