出现此问题的原因是我们正在使用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/