小编Ven*_*tor的帖子

Angular MSAL (v2) 通过重定向登录,在获取令牌之前重定向 3 次或更多次

我有一个 Angular 应用程序 ( v11.2.0 ),它使用 MSAL 进行身份验证。我最近升级到该库的 v2(@azure/msal-angular - ^2.1.1、@azure/msal-browser - ^2.22.0),并且由于 MSAL 更改而进行了一些重构。除了对用户进行身份验证并获取身份验证响应时之外,它的大部分工作方式与以前一样:该过程在成功获取身份验证响应之前循环大约 3 次,每次都会明显刷新应用程序。我看到的大致流程如下:

  • 循环1
  • 导航至应用程序
  • 用户未经过身份验证
  • 处理重定向启动
  • 处理重定向承诺调用但没有正在进行的交互,返回 null
  • 处理重定向结束
  • 登录开始
  • 收到空认证结果
  • 循环2
  • 导航至应用程序
  • 用户未经过身份验证
  • 处理重定向启动
  • 循环3
  • 导航至应用程序
  • 用户未经过身份验证
  • 处理重定向启动
  • 信息 - 获取令牌调用中
  • 登录成功
  • 处理重定向结束
  • 获取令牌启动
  • 收到认证结果

身份验证在我的 app.component.ts 中启动和处理:

ngOnInit() {
   this.msalBroadcastService.inProgress$
      .pipe(
         filter((status: InteractionStatus) => status === InteractionStatus.None)
      )
      .subscribe(async () => {
         if (!this.authenticated) {
            await this.logIn();
         }
      })

   this.msalService.handleRedirectObservable().subscribe({
      next: (result: AuthenticationResult) => {
         if (!this.msalService.instance.getActiveAccount() &&             
            this.msalService.instance.getAllAccounts().length > 0) …
Run Code Online (Sandbox Code Playgroud)

azure-ad-msal angular msal-angular

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

angular ×1

azure-ad-msal ×1

msal-angular ×1