首页 > 解决方案 > 如何配置 msal-angular 拦截器以将访问令牌 (v2) 发送到自己的域 (self)

问题描述

我从 v1 更新到 @azure/msal-angular v2。而且我不知道如何配置它以将访问令牌发送到托管在同一域上的后端。

因此,当我的前端发出请求时/api/fooMsalInterceptor应该以版本 2 格式(而不是版本 1)附加我的访问令牌。

这使其发送版本 1 访问令牌

const msalInterceptorConfig: MsalInterceptorConfiguration = {
  interactionType: InteractionType.Redirect,
  protectedResourceMap: new Map([
    ['/', ['openid']],
  ]),
};

我设法通过添加来“欺骗”它

const msalInterceptorConfig: MsalInterceptorConfiguration = {
  interactionType: InteractionType.Redirect,
  protectedResourceMap: new Map([
    ['/', [`api://${clientId}/access_as_user`]],
  ]),
};

但随后 AzureAD 开始抱怨

AADSTS90009:应用程序正在为自己请求令牌。仅当使用基于 GUID 的应用标识符指定资源时才支持此方案

所以这不是一个选择。如何MsalInterceptor将版本 2 访问令牌发送到/

标签: angularazure-active-directorymsalmsal-angular

解决方案


我不知道这是否是正确的方式,甚至是预期的行为。但是以下配置将 v2 访问令牌发送到我的后端。

const msalInterceptorConfig: MsalInterceptorConfiguration = {
  interactionType: InteractionType.Redirect,
  protectedResourceMap: new Map([
    ['/', [`${clientId}/openid`]],
  ]),
};

推荐阅读