Skype Web SDK Oauth2 授权资源无效

Skype Web SDK Oauth2 authorization invalid resource

我正在尝试使用 Skype Web SDK 将 Skype for Business 与我的应用集成,但我什至无法完成授权。这是我的代码,基于此视频中的代码:https://youtu.be/EyHL1HH9FzE?t=20m20s

public connect() {
    var client_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

    if (!/^#access_token=/.test(location.hash)) {
        console.log("no token");

        location.assign(
            "https://login.microsoftonline.com/common/oauth2/authorize"
            + "?response_type=token"
            + "&client_id=" + client_id
            + "&redirect_uri=" + location.href
            + "&resource=https://webdir.online.lync.com"
        );
    } else {
        console.log("token present");
    }
}

我被重定向到我可以登录的 Microsoft 页面,但是接下来我被重定向回我的应用程序 url:http://myapp/ui/index.html#error=invalid_resource&error_description=AADSTS50001%3a+Resource+identifier+is+not+provided.%0d%0aTrace+ID%3a+0efb74b9-6063-4046-9710-836d43641d00%0d%0aCorrelation+ID%3a+7fcbee4c-e543-4b00-a485-152779f346bb%0d%0aTimestamp%3a+2018-06-13+13%3a52%3a30Z

所以它说错误是

an invalid resource and that the resource identifier is not provided.

我已经从视频中复制了资源部分,并在其他多个教程中看到过

+ "&resource=https://webdir.online.lync.com"

在天蓝色中,我已将 oauth2AllowImplicitFlow 设置为 true,Skype for Business Online 的委派权限也已添加到该应用程序。

an invalid resource and that the resource identifier is not provided.

如果我使用 location.assign,我也可以重现你提到的问题。似乎 CORS 阻止了它。与resource=https://webdir.online.lync.com

无关

Note that security settings, like CORS, may prevent this to effectively happen

解法:

window.location.href = href

请尝试使用以下代码,然后它在我这边可以正常工作。更多信息请参考此article.

 var client_id = "xxxx"
 window.sessionStorage.setItem('client_id', client_id);
 var href = 'https://login.microsoftonline.com/common/oauth2/authorize?response_type=token&client_id=';
 href += client_id + '&resource=https://webdir.online.lync.com&redirect_uri=' + window.location.href;
 window.location.href = href;