.net Core MVC 5 Multiple B2C Authentication

Viewed 131

I have a Web App that is currently authenticating using b2c with flows, its working fine, but I have a requirement where the Web App must have an option to connect to two different B2C Tenants, let's call them B2C1 and B2C2, each of this tenant are not related at all and are tenants from different azure accounts.

What I wanna do is that if a user enters to let's say myapp.com/b2c1 or myapp.com/b2c2 the app must redirect them to the appropriate signinsignup flow.

I believe the concept is called multi tenant, I read this documentation

But what I understand it does is to add a button on the login page flow that redirect me to another login page that allow me to sign in from any B2C account, that´s not what Im trying to accomplish.

I tried something crazy like this in the startup.cs file

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
   .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAdB21"), "AD1", "COOKIE1")
   .EnableTokenAcquisitionToCallDownstreamApi(new string[] { Configuration["WebApi1:Scope"] })
   .AddInMemoryTokenCaches();

services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
   .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAdB21"), "AD2", "COOKIE2")
   .EnableTokenAcquisitionToCallDownstreamApi(new string[] { Configuration["WebApi2:Scope"] })
   .AddInMemoryTokenCaches();            

The web app loads but when I click the login link, an exception shows up that says

InvalidOperationException: No authentication handler is registered for the scheme 'OpenIdConnect'.

Can someone give me some advice to accomplish this requirement?

0 Answers
Related