首页 > 解决方案 > 使用 unprotectedResources 与 Angular 集成的 MSAL

问题描述

我目前正在将 azure AD 集成到我的 Angular 应用程序中......到目前为止,除了它如何处理 HTTP 之外,一切都运行良好。

所以我在应用程序中附加了一个典型的 http 拦截器:

{
  provide: HTTP_INTERCEPTORS,
  useClass: MsalInterceptor,
  multi: true
},

和一些这样的配置......

 MsalModule.forRoot({
  auth: {
      clientId: id,
      authority: auth,
      validateAuthority: true,
      redirectUri: "http://localhost/",
      postLogoutRedirectUri: "http://localhost/dashboard",
      navigateToLoginRequestUrl: true
  },
  framework: {
      unprotectedResources: ["http://localhost/dashboard"]
  },
}, {
    popUp: true
})

因此,当我输入unprotectedResources时,我希望对http://localhost/dashboard的所有 http 请求都无需任何身份验证即可通过。

但是......当我没有登录时,我得到“core.js:7187 ERROR ClientAuthError: User login is required”。在控制台中。

有什么帮助吗?

标签: angularazurehttpazure-active-directorymsal

解决方案


根据他们的文档,截至@azure/msal-angular@1.1.0,protectedResourceMap 支持 minimatch 支持的通配符模式,而 unprotectedResources 已被弃用和忽略。

而是把 protectedResourceMap: null 应该工作

参考:https ://github.com/AzureAD/microsoft-authentication-library-for-js/issues/2217


推荐阅读