出现此问题的原因是我们正在使用API版本'2.0',但是来自“live.com”等外部身份提供者的用户帐户不支持该API版本。为了解决此问题,我们可以通过向访问令牌请求URL中添加“api-version=1.0”参数来使用API版本'1.0'。
示例代码:
MSAL.js(JavaScript版):
// create a ClientApplication object
const msalConfig = {
auth: {
clientId: 'client_id_here',
authority: 'https://login.microsoftonline.com/tenant_id_here',
}
};
const msalInstance = new Msal.UserAgentApplication(msalConfig);
// call the acquireTokenSilent method to authenticate the user
msalInstance.acquireTokenSilent({
scopes: [...requested_scopes]
}).then((accessToken) => {
// use the access token to make API requests
}).catch((error) => {
if (error.name === 'InteractionRequiredAuthError') {
// call the acquireTokenPopup method to prompt the user to sign in
msalInstance.acquireTokenPopup({
scopes: [...requested_scopes]
}).then((accessToken) => {
// use the access token to make API requests
}).catch((error) => {
console.log(error);
})
} else {
console.log(error);
}
});
这里只需要在URL中添加一个api-version参数即可:
// call the acquireTokenSilent method to authenticate the user
msalInstance.acquireTokenSilent({
scopes: [...requested_scopes],
authority: 'https://login.microsoftonline.com/tenant_id_here?api-version=1.0'
}).then((accessToken) => {
// use the access token to make API requests
}).catch((error) => {
if (error.name === 'InteractionRequiredAuthError') {
// call the acquireTokenPopup method to prompt the user to sign in
msalInstance.acquireTokenPopup({
scopes: [...requested_scopes],
authority: 'https://login.microsoftonline.com/
上一篇:AADSTS50013:断言签名验证失败。[原因-找不到密钥,客户端使用的密钥指纹:'xxxx']
下一篇:AADSTS50020错误:来自身份提供者的用户帐户“{EmailHidden}”在租户“MicrosoftServices”中不存在,无法访问该应用程序。