Hi,
I am developing an ASP.NET Core 2.0 application and trying to enable OpenID Authentication against multiple Azure active directories. That means my application is registered in at least to AAD as an Application. I decide - based on a user Input - which AAD should used for authentication.
The Default AAD configuration works fine for one AAD:
services.AddAuthentication(sharedOptions => { sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) .AddAzureAd(options => Configuration.Bind("AzureAd", options)) .AddCookie();
Now if I try to add another one I get the error message:
InvalidOperationException: Scheme already exists: OpenIdConnect
services.AddAuthentication() .AddOpenIdConnect(AuthConstants.1, sharedOptions => { sharedOptions.ClientId = Configuration["AAD1Ad:ClientId"]; sharedOptions.Authority = $"{Configuration["AAD1Ad:Instance"]}{Configuration["AAD1Ad:TenantId"]}"; sharedOptions.UseTokenLifetime = false; sharedOptions.CallbackPath = Configuration["AAD1Ad:CallbackPath"]; sharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.SignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme; }).AddCookie(AuthConstants.AAD1Cookie); services.AddAuthentication() .AddOpenIdConnect(AuthConstants.AAD2, sharedOptions => { sharedOptions.ClientId = Configuration["AAD2Ad:ClientId"]; sharedOptions.Authority = $"{Configuration["AAD2Ad:Instance"]}{Configuration["AAD2Ad:TenantId"]}"; sharedOptions.UseTokenLifetime = false; sharedOptions.CallbackPath = Configuration["AAD2Ad:CallbackPath"]; sharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.SignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme; }).AddCookie(AuthConstants.2Cookie);
Help me please :-)