我的项目的身份验证(Cookie)设置如下,
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.ClaimsIssuer = "xxx.admin";
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
options.LoginPath = "/Login/Index/";
options.AccessDeniedPath = "/Account/Unauthorized/";
options.Cookie.SameSite = SameSiteMode.Strict;
});
我在不同的项目中配置了第二个身份验证选项(OpenIdConnect),如下所示,
services.AddRazorPages().AddMvcOptions(options =>
{
var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
options.Filters.Add(new AuthorizeFilter(policy));
}).AddMicrosoftIdentityUI();
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme).AddMicrosoftIdentityWebApp(options =>
{
Configuration.Bind("AzureActiveDirectoryConnection", options);
options.Events ??= new OpenIdConnectEvents();
options.Events.OnTokenValidated += OnTokenValidated;
options.Events.OnTicketReceived += OnTicketReceived;
//options.Events.OnRedirectToIdentityProvider += OnRedirectToIdentityProvider;
});
现在,我需要将它们组合起来以在我的应用程序中支持多种身份验证类型。我怎样才能做到这一点?