首页 > 解决方案 > 在使用 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));
        });
    });
});

}

标签: angularazure-active-directoryazure-ad-graph-apimsal

解决方案


推荐阅读