With MSAL loginRedirect how can I send the user to the registration variant of the auth page?

bjn 0 Reputation points
2024-05-09T19:27:27.3966667+00:00

I have a React app and I'm using @azure/msal-react/@azure/msal-browser to deal with authentication.

I am not in direct control of the Azure services it's built on, and to be honest don't know much about them or how they're set up. I think it's Azure AD but I'm not even sure about that. Awkwardly, I do not have direct contact with the person in charge of that side of things.

My configuration's authority is set to https://[myapp].b2clogin.com/[myapp].onmicrosoft.com/B2C_1_DEFAULT, if that helps at all.

Logging in and out is working fine. We're using the msal.instance.loginRedirect call.

This sends the user to a log in page, which as far as I can gather is customized by someone on my client's side. It has a regular "sign in" version, but it also has a "don't have an account? sign up now" link which reveals a different form with different fields.

What I want is a way to send a user directly to that version of the page, for example if they click a special "register" button in the app.

I haven't been able to find anything related in the MSAL documentation, which makes me wonder if this is a question specific to the way the auth flow has been configured by this particular client.

I have noticed that after clicking the "sign up now" link the URL of the page changes to something of the form [origin]/B2C_1_DEFAULT/api/CombinedSigninAndSignup/unified?local=signup&.... I wonder if there's some option I can pass in my loginRedirect call to get it to go straight here.

(meta: I can't find any suitable tags. There's no Azure AD tag, and no MSAL tag. And it needs a tag so I picked the most generic one I could find.)

Microsoft Entra
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. James Hamil 22,186 Reputation points Microsoft Employee
    2024-05-10T20:57:43.8966667+00:00

    Hi @bjn , you can use extraQueryParameters. , you can add the prompt=signup parameter to the extraQueryParameters option in the AuthenticationParameters object.

    Here's an example of how you can modify your loginRedirect call to achieve this:

    const authParams = {
      scopes: ["openid", "profile"],
      extraQueryParameters: {
        prompt: "signup"
      }
    };
    
    instance.loginRedirect(authParams);
    
    

    This will add the prompt=signup parameter to the authorization request, which will prompt the user to sign up instead of signing in.

    Note that this will only work if the Azure AD B2C policy has a sign-up flow configured. If there is no sign-up flow configured, the user will be redirected to the regular sign-in page. Another thread to reference here.

    Please let me know if you have any questions and I can help you further.

    If this answer helps you please mark "Accept Answer" so other users can reference it.

    Thank you,

    James