Azure OpenID-调用window.location.href = URI会导致CORS错误

时间:2018-08-31 15:07:45

标签: javascript google-chrome firefox cors openid-connect

我编写了一个Web应用程序,以显示登录Azure Active Directory帐户的工作方式。当用户单击“登录”按钮时,应该会打开Windows的登录页面,以便用户可以在那里登录并返回我的网站。 当我创建登录请求时,Internet Explorer打开“登录”页面-一切正常-但是当我使用Google Chrome或Mozilla Firefox浏览器时,什么也没发生。当我在Chrome或Fireforx中调试网站时,我看到那里的Broser不会在发生CORS错误时执行请求。

Screenshot of the HTML Section

这是我的JavaScript代码:

OpenIDConnect.getAuth = function () {
    var redirect = $('.redirect').val();
    var clientId = $('.client-id').val();

    var redirectEncoded = encodeURIComponent(redirect);
    var url = OpenIDConnect.authorizeURL + "?client_id=" + clientId + "&response_type=" + OpenIDConnect.responsetype + "&redirect_uri=" + redirectEncoded + "&scope=" + OpenIDConnect.scope;
    $.get(url, true, function (data) {
        window.location.href = url;
    }).fail(function (error) {
        $('#resultCode').val(error.responseText);
    });
}

此错误是结果:

Failed to load https://login.microsoftonline.com/d784835f-2cab-48ad-840f-6c85e48fa1cf/oauth2/v2.0/authorize?client_id=b084ff12-8c41-4eab-9d2f-09fc4860fd19&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A7107%2Fopenidconnect%2F&scope=openid%20email%20profile%20offline_access: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:7107' is therefore not allowed access.

可能有趣的部分是:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:7107' is therefore not allowed access.

此情况发生在Google Chrome和Firefox中,但不在Internet Explorer中。现在,我不知道该怎么做才能在Chrome和Firefox中也能正常工作。 在我的Web项目中,我使用:

  • jQuery v1.10.2
    • MixItUp v2.1.11
    • 宏伟的弹出窗口-v1.1.0
  • Bootstrap v3.3.7

0 个答案:

没有答案