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