microsoft-authentication-library-for-js: redirectUri getting ignored

I include redirectUri when I invoke msal.js but after logging in on Azure AD B2C login page, user gets redirected to the page he/she came from, instead of the redirectUri I specify. Why is this happening?

Here’s my code

<script>
   var instance = 'https://login.microsoftonline.com/tfp/';
   var tenant = 'myazureadb2ctenant.onmicrosoft.com';
   var signInPolicy = 'B2C_1_SignUp_SignIn';
   var applicationId = 'my-application-id';
   var scopes = ['https://myazureadb2ctenant.onmicrosoft.com/webclient/readaccess'];
   var redirectUri = 'https://example.com/member';
   var authority = `${instance}${tenant}/${signInPolicy}`;

   var clientApplication = new Msal.UserAgentApplication(
       applicationId,
       authority,
       function (errorDescription, token, error, tokenType) {
          // Handle error
       },
       {
            redirectUri: redirectUri
       });

       var mySignInFunction() {
              clientApplication.loginRedirect(scopes);
       };
</script>

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26 (11 by maintainers)

Most upvoted comments

@spottedmahn I can’t thank you enough!!!

@spottedmahn I have tears in my eyes!!! It’s working!!!

FYI, the code that controls the redirect behavior is here.

It is pretty simple. If navigateToLoginRequestUrl true then send the user back othewise don’t.

Any idea why the redirectUri is getting ignored?

I would turn on Preserve Log in Chrome debug tools

image

Then you can see the URL(s) your app navigated to. That might help diagnosis the issue.

I troubleshot the opposite of your problem w/ a fellow dev the other day. Turns out our AuthentactionGuard was causing problems and seeing URL the app navigated to help identify it.