为什么我无法仅通过Edge浏览器通过Sharepoint自定义Web部件通过Microsoft Graph Explorer进行身份验证

时间:2019-06-12 09:55:34

标签: sharepoint sharepoint-online spfx

我已经在共享点在线上部署了自定义Web部件,并在其中通过Microsoft Graph Explorer进行了身份验证。

它已通过Sharepoint自定义Web部件在 Chrome IE Firefox 中成功进行了身份验证,但未在 Edge 中进行了身份验证>。

在Edge中,我遇到以下错误:

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)

enter image description here

这是我的方法,在调用Microsoft图形资源管理器API(“ https://graph.microsoft.com”)时,我发现在Chrome,IE和Firefox中,API提供了响应,但是在Edge中,它却很重要并引发错误。

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); });
  }

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我在sharepoint.stackexchange上问了同样的问题,在那里我得到了一个对我有用的答案。

后端似乎有所变化,因此代码已在Edge和IE中停止工作。

作为一种变通办法,目前,建议您显式设置标头值。

您需要为标题添加以下代码,不要忘记从ISPHttpClientOptions模块导入@microsoft/sp-http

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

之后,您的完整代码如下:

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); });
}