How do I make 'forgot password' working in react-aad-msal with Azure AD B2C?

血红的双手。 提交于 2019-12-01 18:57:50

问题


I am using react-aad-msal with Azure AD B2C. I have sign-in and sign-out working. However, when I click 'Forgot your password?', the auth window disappears and nothing happens.

It seems I need to specify name of my 'forgot password' policy, but I do not know where to put it.

Based on Tony's answer added this code to my App's render:

if (window.location.href.indexOf("error_description=AADB2C90118") >= 0)
    {
      return <AzureAD
      provider={
        new MsalAuthProviderFactory({
          authority: 'https://login.microsoftonline.com/tfp/x5aaas.onmicrosoft.com/B2C_1_PwdReset', 
          clientID: 'a1568977-3095-4bf6-a6d6-c10c87658488',
          scopes: ['https://x5aaas.onmicrosoft.com/ui/use'],
          type: LoginType.Redirect,
          postLogoutRedirectUri: window.origin,
        })
      }
      unauthenticatedFunction={this.unauthenticatedFunction}
      userInfoCallback={this.userJustLoggedIn}
      authenticatedFunction={this.authenticatedFunction}
    />;
    }

I see that after I click "Forgot password?", the condition is true, and return happens. However, the window for password reset does not show up and I get redirected back to my app URL.

Any suggestions?


回答1:


What I did was create a Route in my App.js:

          <Route
            path="/forgot"
            component={() => {
              window.location.href = forgotPasswordUrl;
              return null;
            }}
          />

Then, in the constructor

if (window.location.hash.indexOf('AADB2C90118') >= 0) {
  history.push('/forgot');
}

And that works.




回答2:


When using a combined sign-up/sign-in policy in Azure B2C, users have to handle the forgot password scenario themselves. You can find more detailed comments here.

A sign-up or sign-in user flow with local accounts includes a "Forgot password?" link on the first page of the experience. Clicking this link doesn't automatically trigger a password reset user flow.

Instead, the error code AADB2C90118 is returned to your application. Your application needs to handle this error code by running a specific user flow that resets the password. To see an example, take a look at a simple ASP.NET sample that demonstrates the linking of user flows.



来源:https://stackoverflow.com/questions/55718030/how-do-i-make-forgot-password-working-in-react-aad-msal-with-azure-ad-b2c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!