angular-oauth2-oidc 忘记密码流程

sim*_*n90 4 azure-ad-b2c angular angular-oauth2-oidc

我正在使用 angular-oauth2-oidc 在我的 Angular (8) 应用程序上设置 B2C。我有一个登录和退出策略,我已经正确地设置了 angular-oauth2-oidc 服务。目前我正在使用包含忘记密码链接的标准 Microsoft 登录页面。我已经在 B2C 中为忘记密码创建了流程,但我正在努力将它集成到 angular-oauth2-oidc 中。当我点击忘记密码链接时,B2C 抛出错误“AADB2C90118”;为确保流程正确,我测试了流程,创建了一个 AuthConfig 文件,例如我为登录策略创建的文件;只需使用忘记密码流信息(在这种情况下,用户单击按钮并重定向到忘记密码发布者) - 并且它可以工作。

AuthConfig 文件中是否有任何变量可以设置为忘记密码端点或任何可以处理此问题的方法?

Cap*_*chi 6

我按照 angular-oauth2-oidc 库的创建者的建议设法让它工作。

首先,我创建了一个 OAuthErrorEventParams 接口,我可以将我的 OAuthErrorEvent.params 转换为:

export interface OAuthErrorEventParams {
   error: string;
   error_description: string;
   state: string;
 }
Run Code Online (Sandbox Code Playgroud)

然后我创建了这个常量来代表我的 RedirectUrl 重定向到密码重置流程:

export const PasswordResetUrl = 'https://[tenantname].b2clogin.com/[tenantname].onmicrosoft.com/oauth2/v2.0/authorize?' +
    'p=[PasswordResetFlowName]' +
    '&client_id=' + authConfig.clientId +
    '&nonce=defaultNonce' +
    '&redirect_uri=' + window.location.origin + '/index.html' +
    '&scope=openid' +
    '&response_type=id_token' +
    '&prompt=login';
Run Code Online (Sandbox Code Playgroud)

最后,在我处理 Auth 服务设置和配置的组件中,我添加了以下内容:

constructor(private oauthService: OAuthService) {
     this.configure();
     this.oauthService.events.subscribe(e => {
       if (e instanceof OAuthErrorEvent) {
         const parm = e.params as OAuthErrorEventParams;
         if (parm.error === 'access_denied' && parm.error_description.includes('AADB2C90118')) {
           // redirect to forgot password flow
           window.location.href = PasswordResetUrl;
         } else if (parm.error === 'access_denied' && parm.error_description.includes('AADB2C90091')) {
           // user has cancelled out of password reset
           this.oauthService.initLoginFlow();
         }
       }
     });
     this.oauthService.tryLoginImplicitFlow();
   }
Run Code Online (Sandbox Code Playgroud)

我真的希望这对某人有所帮助,因为在登陆这里之前我花了很长时间找到解决方案。