用户点击取消时如何处理?

问题描述 投票:0回答:1

我已经从 Azure B2C 中的自定义策略入门包中实现了 PasswordChange 策略。当用户完成更改密码流程(包括重定向回角度应用程序中的页面)时,该策略可以正常工作。太棒了。

但是,如果用户单击 B2C 更改密码流程中的取消选项,我会在 Angular 应用程序中收到运行时错误,并且我不知道如何处理此问题?

main.ts:6 ERROR Error: Uncaught (in promise): Error: NG04002: Cannot match any routes. 
URL Segment: 'login-failed'
Error: NG04002: Cannot match any routes. URL Segment: 'login-failed'
   at ApplyRedirects.noMatchError (router.mjs:3656:16)
  at router.mjs:3638:28
  at catchError.js:10:39

还有另一个错误:

core.mjs:8400 ERROR ServerError: access_denied: AADB2C90091: The user has cancelled 
entering self-asserted information.
Correlation ID: 931f36f0-640e-461b-84c0-3c4fa0ea04c0
Timestamp: 2023-11-03 03:24:59Z

at ResponseHandler.validateServerAuthorizationCodeResponse (ResponseHandler.mjs:76:19)
at AuthorizationCodeClient.handleFragmentResponse (AuthorizationCodeClient.mjs:83:25)

与注册和登录流程不同,似乎没有办法在客户端中捕获此错误,我可以在其中捕获错误并执行适当的重定向。

调用的代码:

  changePassword() {
    this.authService.loginRedirect({
    authority: environment.b2cPolicies.authorities.changePassword.authority,
    scopes: environment.apiConfig.scopes
   });
  }

环境中的值很好,因为它们在用户完成更改密码后起作用。我只需要知道当用户单击“取消”时该怎么做!

这是在注册和重置密码流程中处理取消的代码:

    // Listen for error events
this.msalBroadcastService.msalSubject$
  .pipe(filter((msg: any) => msg.eventType === EventType.LOGIN_FAILURE),
    tap((msg: any) => {
      const error = msg.error as InteractionRequiredAuthError;
     
      if (error && error.errorMessage && error.errorMessage.includes('AADB2C90091')) {
         // Redirect to login page. User has cancelled self-asserted or change password.
         
        this.authService.instance.loginRedirect();
      }
      else if (error && error.errorMessage && 
         error.errorMessage.includes('AADB2C90118')) {
        // Trigger the Password Reset user journey
        this.authService.loginRedirect({
          authority: environment.b2cPolicies.authorities.resetPassword.authority,
          scopes: environment.apiConfig.scopes
        });
      }
    })
  )
  .subscribe();
angular azure-ad-b2c azure-ad-b2c-custom-policy
1个回答
0
投票

令人惊讶的是,我更改了错误处理并删除了过滤器。现在可以了!你不知道为什么!

    // Listen for error events
this.msalBroadcastService.msalSubject$
  .pipe(
    tap((msg: any) => {
      const error = msg.error as InteractionRequiredAuthError; 
      if (error && error.errorMessage && error.errorMessage.includes('AADB2C90091')) {
         // Redirect: User has cancelled self-asserted or change password.  
        this.authService.instance.loginRedirect();
      }
      else if (error && error.errorMessage && error.errorMessage.includes('AADB2C90118')) {
        // Trigger the Password Reset user journey
        this.authService.loginRedirect({
          authority: 
          environment.b2cPolicies.authorities.resetPassword.authority,
          scopes: environment.apiConfig.scopes
        });
      }
    })
  )
  .subscribe();

现在这似乎适用于多个测试,并且注册登录流程中没有回归。

可以,但不知道为什么!

© www.soinside.com 2019 - 2024. All rights reserved.