I请求OAuth2
服务器的authorization code
。 我的目的是授权用户与我的微软应用程序。 Refered DocumentOAuth2访问原始错误
我对GET呼叫尝试:
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();
}
但是这给下面的错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
然后我加入req.setRequestHeader("Access-Control-Allow-Origin", "*");
,但它提供了以下错误:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
你需要在服务器上配置这一点,而不是角应用 – jonrsharpe
@jonrsharpe什么你的意思“做你需要在服务器上配置它“? –
我的意思是你提出请求的服务器。尽管这似乎超出了你的控制范围。 – jonrsharpe