为什么我无法仅在 Edge 浏览器中通过 Sharepoint 自定义 Web 部件使用 Microsoft Graph Explorer 进行身份验证 [英] Why I am not able to authenticate with Microsoft Graph Explorer through Sharepoint Custom Web Part only in Edge Browser
问题描述
我已经在 sharepoint online 上部署了一个自定义 Web 部件,我在其中通过 Microsoft Graph Explorer 进行了身份验证.
I have deployed a custom web part on sharepoint online, in which I am authenticate with Microsoft Graph Explorer.
在 Chrome、IE 和 Firefox 中通过 Sharepoint 自定义 Web 部件成功通过身份验证,但在 Edge 中未通过身份验证>.
It is authenticated through Sharepoint Custom Web Part successfully in Chrome, IE and Firefox but not authenticated in Edge.
在 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)
这是我的方法,我发现在调用 microsoft graph explorer API("https://graph.microsoft.com
") 时,在 Chrome、IE 和 Firefox 中该 API 提供响应,但在 Edge 中它进入 catch 部分并抛出错误.
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); });
}
感谢任何帮助.
推荐答案
我在 sharepoint.stackexchange,我有一个适合我的答案.
I had asked the same question on sharepoint.stackexchange, there I have got an answer that works for me.
后端似乎发生了一些变化,因此代码在 Edge 和 IE 中有点停止工作.
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.
您需要为标题添加以下代码,不要忘记从@microsoft/sp-http
模块导入ISPHttpClientOptions
:
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); });
}
这篇关于为什么我无法仅在 Edge 浏览器中通过 Sharepoint 自定义 Web 部件使用 Microsoft Graph Explorer 进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!