title: Blazor login path for multiple authentication schemes (AAD and AB2C)
body: <p>I want to use Azure AD and Azure B2C in one application. I registered both authentication schemes which works fine.</p>
  <p>Now I want to allow the user to decide which scheme should be used by clicking a &quot;login with AD&quot; or &quot;login with B2C&quot; button. Clicking on one of the buttons should redirect the user to the correct login.</p>
  <p>I'm able to do this for AD by using the link <code>MicrosoftIdentity/Account/SignIn</code>. To do this, it's necessary to use <code>services.AddControllersWithViews().AddMicrosoftIdentityUI()</code></p>
  <p>So, how do I get a link like above for B2C?</p>
  <p>Here is my code:</p>
  <pre><code>        public static void AddAzureADAuthenticationApp(this IServiceCollection services, IConfigurationSection configuration)
          {
              services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
                  .AddMicrosoftIdentityWebApp(options =&gt;
                  {
                      configuration.Bind(options);
                      options.Events.OnTokenValidated = async context =&gt;
                      {
                          await AuthorizationHelper.ValidateAADAppToken(context);
                      };
                  })
                  .EnableTokenAcquisitionToCallDownstreamApi().AddInMemoryTokenCaches();
  
              services.AddControllersWithViews(options =&gt;
              {
                  var policy = new AuthorizationPolicyBuilder(OpenIdConnectDefaults.AuthenticationScheme)
                      .RequireAuthenticatedUser()
                      .AddRequirements(new AzureADAuthorizationRequirement()).Build();
                  options.Filters.Add(new AuthorizeFilter(policy));
              })
              .AddMicrosoftIdentityUI(); 
  
  
              services.AddAuthorization(config =&gt;
              {
                  var policy = new AuthorizationPolicyBuilder(OpenIdConnectDefaults.AuthenticationScheme)
                      .RequireAuthenticatedUser()
                      .AddRequirements(new AzureADAuthorizationRequirement()).Build();
                  config.AddPolicy(Constants.PolicyInternalUsers, policy);
              });
  
          }
  
          public static void AddAzureB2CAuthenticationApp(this IServiceCollection services, IConfigurationSection configuration, bool RequireAccountNum = false)
          {
              services.AddAuthentication()
                  .AddMicrosoftIdentityWebApp(options =&gt;
                  {
                      configuration.Bind(options);
                      options.SignInScheme = Constants.B2CAuthenticationScheme;
                      options.ResponseType = &quot;code id_token&quot;;
                      options.Scope.Clear();
                      options.Scope.Add(&quot;https://graph.microsoft.com/openid&quot;);
                      options.Events.OnTokenValidated = async context =&gt;
                      {
                          await AuthorizationHelper.ValidateB2CAppToken(context, RequireAccountNum);
                      };
                  }, openIdConnectScheme: Constants.B2CAuthenticationScheme, cookieScheme: Constants.B2CCookieScheme)
                  .EnableTokenAcquisitionToCallDownstreamApi().AddInMemoryTokenCaches();
  
              services.AddControllersWithViews(options =&gt;
              {
                  var policy = new AuthorizationPolicyBuilder(FischerLib.Extensions.Constants.B2CAuthenticationScheme)
                  .RequireAuthenticatedUser()
                  .AddRequirements(new AzureB2CAuthorizationRequirement(RequireAccountNum)).Build();
  
                  options.Filters.Add(new AuthorizeFilter(policy));
              })
              .AddMicrosoftIdentityUI();
  
              services.AddAuthorization(config =&gt;
              {
                  var policy = new AuthorizationPolicyBuilder(FischerLib.Extensions.Constants.B2CAuthenticationScheme)
                      .RequireAuthenticatedUser()
                      .AddRequirements(new AzureB2CAuthorizationRequirement(RequireAccountNum)).Build();
                  config.AddPolicy(Constants.PolicyExternalUsers, policy);
              });
          }
  </code></pre>
  <p>At the moment I'm using two controller which have authorize attributes restricted to the scheme. Accessing these controller redirects the user to the login.</p>
  <p>But this is not the way which I want to use. After the code above is part of a library and I would like to avoid having to ad the controller in every project.</p>
  <p>I know that there is a property <code>LoginPath</code> if I use a different scheme like cookies but I can't set this property in <code>AddMicrosoftIdentityWebApp(...)</code></p>
  <p>Thank you very much!</p>
  <p>Markus</p>