Code: Select all
System.InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.
Meine Anwendung soll mehrere Authentifizierungsschemata (oder möglicherweise Autorisierungsschemata?) Aufweisen, die im Startup hinzugefügt/konfiguriert werden. Verbotener Fehler stattdessen? wurde mindestens einmal eingestellt, ist aber tatsächlich mehrmals eingestellt - warum ist das ein Problem? Warum kann es nicht funktionieren, was der "Standard" sein sollte? Muss ich eine Authentifizierung hinzufügen, die tatsächlich als Standard fungiert? Ich bin mir nicht sicher, ob ich dem IserviceCollection nicht mehrfache Authentifizierungspunkte hinzufügen kann, da Anrufe wie .addjwtbearer eine weitere Authentifizierungspunkte hinzufügen. Ich nehme an, ich verstehe nicht wirklich, wie man tatsächlich ein Standard -Herausforderungsschema festlegt, wenn es mehrere Authentifizierungspunkte gibt. < /P>
Code: Select all
//services var = IServiceCollection services
// Adding authentication
var firstUserpoolName = userpools.First().Key;
var authenticationBuilder = services.AddAuthentication(options =>
{
options.DefaultScheme = firstUserpoolName;
options.DefaultChallengeScheme = firstUserpoolName;
});
// Adding authentication for each userpool name
foreach (var userpool in userpools)
{
var userpoolDetails = userpool.GetChildren().ToList();
var userpoolAuthenticationBuilder = services.AddAuthentication();
userpoolAuthenticationBuilder.AddJwtBearer(userpool.Key, options =>
{
options.Audience = userpoolDetails.FirstOrDefault(d => d.Key == "Audience")?.Value;
// More options set here in actual code
});
}
string prioritySystem = Configuration["Priority_System"].ToLower();
string loginPath = string.Format("/{0}/login", prioritySystem);
//Adding cookie authentication
var cookiesAuthenticationBuilder = services.AddAuthentication(options =>
{
// Adding these options allows for the correct HttpContext to be accessible in any middleware
options.DefaultChallengeScheme = AuthenticationSchemes.CookieAuthenticationDefault;
options.DefaultAuthenticateScheme = AuthenticationSchemes.CookieAuthenticationDefault;
});
cookiesAuthenticationBuilder.AddCookie(options =>
{
options.LoginPath = loginPath;
options.EventsType = typeof(CustomCookieAuthenticationEvents);
// More options set here in actual code
});
// Adding SSO authentication
var ssoConfig = Configuration.GetSection(AuthenticationSchemes.OIDC_SSO);
if (ssoConfig.Exists())
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = AuthenticationSchemes.CookieAuthenticationDefault;
options.DefaultSignInScheme = AuthenticationSchemes.CookieAuthenticationDefault;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
});
}
else
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = AuthenticationSchemes.CookieAuthenticationDefault;
options.DefaultSignInScheme = AuthenticationSchemes.CookieAuthenticationDefault;
});
}
if (ssoConfig.Exists())
{
// Setup SSO auth
services.Configure(builderSSOConfig);
var serviceProvider = services.BuildServiceProvider();
var builderAuthOptions = serviceProvider.GetService();
services.AddAuthentication().AddOpenIdConnect(AuthenticationSchemes.OIDC_SSO, options =>
{
options.CallbackPath = "/signin-oidc";
// More options set here in actual code
});
}