Why I am not able to authenticate with Microsoft Graph Explorer through Sharepoint Custom Web Part only in Edge Browser

倾然丶 夕夏残阳落幕 提交于 2019-12-23 04:41:40

问题


I have deployed a custom web part on sharepoint online, in which I am authenticate with Microsoft Graph Explorer.

It is authenticated through Sharepoint Custom Web Part successfully in Chrome, IE and Firefox but not authenticated in Edge.

In Edge I've getting below error:

description: "Invalid argument"
message: "Invalid argument"
number: -2147418113
stack: "TypeError: Invalid argument at Anonymous function (https://spoprod-a.akamaihd.net/files/sp-client-prod_2019-05-31.012/sp-pages-assembly_en-us_80b161431b1b8ce356b58dd5ab1df0cc.js:1178:42819)

This is my method in which I found that at the time of calling microsoft graph explorer API("https://graph.microsoft.com"), in Chrome, IEand Firefox the API provides the response, but in Edge it goes in catch part and throws error.

private _getListApplications(param): Promise<any> {
  return this.context.aadHttpClientFactory.getClient('https://graph.microsoft.com')
    .then((client: AadHttpClient) => {
     return client.get("https://graph.microsoft.com/beta/applications",AadHttpClient.configurations.v1);
     }).then((responseListAllApps: SPHttpClientResponse) => {
      return responseListAllApps.json();
     }).catch(err => { console.log('errr', err); });
  }

Any help is appreciated.


回答1:


I had asked the same question on sharepoint.stackexchange, there I have got an answer that works for me.

It looks like there is some change in the back-end because of which the code has kinda stopped working in Edge and IE.

As a workaround, for now, would suggest that you set the header values explicitly.

You need to add the below code for headers, don't forget to import ISPHttpClientOptions from @microsoft/sp-http module:

let httpOptions: ISPHttpClientOptions = {
   headers: {
      "accept": "application/json",
      "content-type": "application/json"
   }
};

After that your full code will be as below:

private _getListApplications(param): Promise<any> {

    let httpOptions: ISPHttpClientOptions = {
        headers: {
            "accept": "application/json",
            "content-type": "application/json"
        }
    };

  return this.context.aadHttpClientFactory.getClient('https://graph.microsoft.com')
  .then((client: AadHttpClient) => {
      return client.get("https://graph.microsoft.com/beta/applications",AadHttpClient.configurations.v1, httpOptions);
      }).then((responseListAllApps: SPHttpClientResponse) => {
         return responseListAllApps.json();
         }).catch(err => { console.log('errr', err); });
}


来源:https://stackoverflow.com/questions/56559338/why-i-am-not-able-to-authenticate-with-microsoft-graph-explorer-through-sharepoi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!