angular - 在使用 MSAL-Angular 并为 Azure Active Directory 图形 api 请求 access_token 时,它提供了带有 Microsoft 图形 api 的 aud 的令牌
问题描述
在使用 MSAL-Angular 并为 Azure Active Directory 图形 api( https://graph.windows.net/ )请求 access_token 时,它使用 Microsoft 图形 api( https://graph.microsoft.com)的 aud 提供令牌
我需要调用 azure active directory graph api,因为 Microsoft graph api 处于 beta 版本。现在,当我使用 msalService 获取 Azure Active Directory 图形 api 的 access_token 时,它会提供带有 microsoft graph api 的 aud 的令牌。当我尝试使用该令牌时,它会给出“您的访问令牌已过期”的错误。请在提交请求之前更新它。即使令牌具有有效时间。
我正在使用下面的打字稿代码来生成 access_token public async getAccessToken(endpointUri: string): Promise {
this.accessToken = '';
const scopes = this.msalService.getScopesForEndpoint(endpointUri);
return new Promise<boolean>((resolve, reject) => {
this.msalService.acquireTokenSilent(scopes)
.then(accessToken => {
this.accessToken = accessToken;
resolve(true);
// tslint:disable-next-line: promise-function-async
}).catch(() => {
return this.msalService.acquireTokenPopup(scopes)
.then(token => {
this.accessToken = token;
resolve(true);
})
.catch((error) => {
reject(new Error(error));
});
});
});
}
解决方案
推荐阅读
- json - 如何在 Postgres 中连接 JArray 元素?
- c# - Xamarin:从本地文件(不是资源)导入 SKBitmap
- php - Wordpress - Use image from URL as a post thumbnail
- json - 如何在嵌套的 Pentaho 中获取路径 Json?
- javascript - 高效地循环数以千计的数组项并对不在本地存储中的每个项进行 api 调用
- javascript - 如何在 javascript 函数中使用接收到的消息中的变量?
- javascript - 如何更改 JavaScript 中的背景颜色?
- php - 试图获取非对象的属性“密码”
- angular - Angular 9:使用命名函数作为 then()、listen() 和 subscribe() 的参数的范围问题
- ssl - curl:(60)SSL证书问题:自签名证书