Search code examples
oauthazure-active-directoryskype-for-business

Skype Web SDK Oauth2 authorization invalid resource


I am trying to integrate Skype for Business with my app using Skype Web SDK, but I cannot even complete authorization. This is my code based on the code from this video: 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");
    }
}

I am being redirected to the microsoft page, where I can log in, however next I am being redirected back to my app with the following 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

So it says the error is

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

I have copied the resource part from the video and have seen it in multiple other tutorials

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

In azure I have set oauth2AllowImplicitFlow to true and delegated permissions for Skype for Business Online are also added to that app.


Solution

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

    I also can reproduce the issue you mentioned if I use location.assign. It seems that CORS prevent it. It is not related with resource=https://webdir.online.lync.com

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

    Solution:

    window.location.href = href
    

    Please have a try to use the following code, then it works correctly on my side. For more information, please refer to this 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;