这是我们的装置。我们有
Program.cs中的身份服务器配置
builder.Services
.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
builder.Services
.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
// see https://docs.duendesoftware.com/identityserver/v6/fundamentals/resources/
options.EmitStaticAudienceClaim = true;
options.IssuerUri = configuration["IssuerUri"];
})
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = b =>
b.UseMySql(conString, serverVersion, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = b =>
{
b.UseMySql(conString, serverVersion, sqlOptions => sqlOptions.MigrationsAssembly(migrationsAssembly));
};
})
.AddAspNetIdentity<ApplicationUser>();
builder.Services.AddAuthentication(options => {
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultForbidScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
return builder.Build();在那之后,我们打电话
app.useAuthorization();
app.useAuthentication();当web应用程序试图从身份服务器url (/.知名/ openid -配置)获取openid配置时,我们将得到以下错误:
System.InvalidOperationException:没有找到DefaultAuthenticateScheme,也没有在IdentityServerOptions上配置CookieAuthenticationScheme。
(在Microsoft.AspNetCore.Http.AuthenticationManagerExtensions.GetCookieAuthenticationSchemeAsync(HttpContext上下文中)在//src/IdentityServer/Extensions/HttpContextAuthenticationExtensions.cs:line 54中
在Duende.IdentityServer.Services.DefaultUserSession.AuthenticateAsync() ( //src/IdentityServer/Services/Default/DefaultUserSession.cs:line 135 )
在Duende.IdentityServer.Services.DefaultUserSession.GetSessionIdAsync()在//src/IdentityServer/Services/Default/DefaultUserSession.cs:line 215号
在Duende.IdentityServer.Services.DefaultUserSession.EnsureSessionIdCookieAsync() ( //src/IdentityServer/Services/Default/DefaultUserSession.cs:line 226 )
在Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext上下文中,//src/IdentityServer/Hosting/IdentityServerMiddleware.cs:line 55中的IEndpointRouter路由器、IUserSession会话、IEventService事件、IIssuerNameService issuerNameService、IBackChannelLogoutService backChannelLogoutService)
在Duende.IdentityServer.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext上下文中,//src/IdentityServer/Hosting/MutualTlsEndpointMiddleware.cs:line 94中的IAuthenticationSchemeProvider方案)
(在Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext上下文中)
(在Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext上下文中)在//src/IdentityServer/Hosting/DynamicProviders/DynamicSchemes /DynamicSchemeAuthenticationMiddleware.cs:line 47中
在Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.g__InvokeCoreAwaited|15_0(HttpContext上下文中,任务1 policyTask)
(在Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext上下文中)在//src/IdentityServer/Hosting/BaseUrlMiddleware.cs:line 27中
(在Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext上下文中)
发布于 2022-04-27 06:23:23
我检查了你的密码,发现了两个错误:
1,如果使用cookie身份验证,并设置如下:

您需要修改代码如下:
builder.Services.AddAuthentication(options =>
{
......
})
.AddCookie( "Cookies",options =>
{
......;
})2 .你需要移动密码:
app.useAuthentication();在前面
app.useAuthorization(); 您可以修改代码,然后再试一次,如果您可以共享更多相关代码,我可以为您进行测试。
更新:尝试设置您的IdentityServer Auth选项:
builder.Services
.AddIdentityServer(options =>
{
......
options.Authentication.CookieAuthenticationScheme= ....
options.Authentication.CookieLifetime = .....
.....
}); 您可以跟随文档:http://docs.identityserver.io/en/latest/reference/options.html#authentication
https://stackoverflow.com/questions/72017977
复制相似问题