Azure AD B2C with MSAL change redirect url on success

3.1k Views Asked by At

I have a React app which uses MSAL msal-react v1.3.1. I am using loginRedirect method to redirect a predefined user flow configured in Azure B2C for password reset. The current behaviour is that when the password reset is complete it redirects back to the page that first invoked the redirect to AD B2C once it has completed successfully.

Is there a way to change the redirect url when the flow has completed to something like below?

instance.loginRedirect({
    authority: `${config.authentication.authority}/${config.authentication.flow.register}`,
    redirectUri: window.location.href + '?success=true'
});

I have tried to set the redirectUri and postLoginRedirectUri which don't appear to change the outcome.

2

There are 2 best solutions below

0
On

What I had to do in this situation was set the navigateToLoginRequestUrl to false where you set up your msal. Example of someone's code with the navigateToLoginRequestUrl option: https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/3818

Then maybe you could use the state option to pass any information you want to the return URL instead of a query parameter on returnURL. But I don't quite see the point here.

instance.loginRedirect({
        authority: `${config.authentication.authority}/${config.authentication.flow.register}`,
        redirectUri: window.location.href,
        state: 'success'
});
0
On

There appears to be a restriction on the redirectUrl as described here.

The redirect url must be registered with the application and cannot contain wildcards or query string parameters.