Where can I set validateAuthority to false when setting B2C redirect urls to b2clogin.com

Viewed 2234

According to the Set redirect URLs to b2clogin.com documentation, we need to mark validateAuthority as false.

Do you know where should put this following code? Is that at startup.cs?

this.clientApplication = new UserAgentApplication( env.auth.clientId, env.auth.loginAuthority, this.authCallback.bind(this), { validateAuthority: false } );
2 Answers

The key point to that documentation is that when you instantiate MSAL, you should set ValidateAuthority to false in whichever form the specific MSAL library you are using supports it.

The code snippet in the documentation is specifically for MSAL.js, which the snippet is probably using for a single page application (SPA) where this code would go in the top-level init code in index.html.

For C# web applications (assuming that's what you're interested in based on your mention of startup.cs:

When you try to login with your B2C account into this app with b2clogin.com endpoints , you get following error message: Authority validation is not supported for this type of authority. It shows as below screenshot:

enter image description here

Resolution:

As Saca said, it should set the the MSAL client's ValidateAuthority property to be false.

For this ASP.NET Web App, we can just change the ValidateAuthority property by adding it in OnAuthorizationCodeReceived event handler from Startup.Auth.cs file:

 ConfidentialClientApplication cca = new ConfidentialClientApplication(ClientId, Authority, RedirectUri, new ClientCredential(ClientSecret), userTokenCache, null) { ValidateAuthority = false} ;
         

In the TasksController.cs file, you can also set it here:

 ConfidentialClientApplication cca = new ConfidentialClientApplication(Startup.ClientId, Startup.Authority, Startup.RedirectUri, new ClientCredential(Startup.ClientSecret), userTokenCache, null) { ValidateAuthority = false} ;
Related