score:2

Accepted answer

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.

score:0

Using msal-react and msal-browser I was able to get the Azure AD B2C password reset page to appear using the following code (assuming you created a password reset user flow named B2C_1_RESET):

import { useMsal } from "@azure/msal-react";
import { EventType } from '@azure/msal-browser';

....

const { instance, inProgress, accounts } = useMsal();

// MSAL Logging
//instance.setLogger(new Logger(loggerCallback));

const callbackId = instance.addEventCallback((message) => {
    if (message.eventType === EventType.LOGIN_FAILURE){
      if (message.error.errorMessage.includes("AADB2C90118")) { // The user has forgotten their password.
        const authority = "https://<your_domain>.b2clogin.com/crowdalert.onmicrosoft.com/B2C_1_RESET";
        instance.loginRedirect({authority: authority})
      }
    }
});

score:0

Credit to Ian for the hint.

You should add an extra condition in case the user cancels their attempt to change reset their account credentials. This way they are redirected back to login instead of getting stuck on your app.

import { useMsal } from "@azure/msal-react";

export default MyComponent = () => {

// other code

const { instance, accounts, inProgress } = useMsal();

instance.addEventCallback((message: any) => {
    if (message.eventType === EventType.LOGIN_FAILURE && message.error.errorMessage.includes("AADB2C90118")) {
      // The user has forgotten their password.
      instance.loginRedirect(passwordResetRequest);
    } else if (message.eventType === EventType.HANDLE_REDIRECT_END && inProgress === InteractionStatus.None) {
      instance.loginRedirect(loginRequest);
    }
  });

// rest of component

};

score:1

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.


Related Query

More Query from same tag