ASP.NET Core 6 IdentityServer(DUENDE):未找到defaultauthenticatescheme或在IdentityServeroptions上配置的cookieAthenticationscheme
所以这是我们的设置。我们拥有
- Angular Web应用程序
- Identity Server API(ASP.NET Core 6,Duende Identity Server)
Indentity Server在 program.cs.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应用程序试图获取OpenID时 呼叫从身份服务器URL(/.well-newand/openid-configuration)配置的配置,我们遇到此错误:
system.invalidoperationException:未找到defaultauthenticatescheme或在IdentityServeroptions上配置的cookiuthenticationsCheme。
在Microsoft.aspnetcore.http.authenticationmanagerextensions.getCookieAuthentIcationsChemeAsync(httpcontext Context)in//src/indistityserver/entistityserver/extensions/htttpcontextextextextextectextextextensions.cs.cs.cs.cs.cs.cs.cs: 在duende.IdentityServer.Services.defaultUsersession.authentIcateAsync()中in//>/>/>/>/>/>/>/ 在duende.indistityserver.services.defaultusessession.getSessionIdasync()in//src/sidentityserver/services/default/default/default/defaultusersession.cs:line 215
上
在duende.IdentityServer.Services.DefaultUsersessessessessessessessessessessessessessesseessionIdCookieAsync()中 at Duende.IdentityServer.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IIssuerNameService issuerNameService, IBackChannelLogoutService backChannelLogoutService) in //src/IdentityServer/Hosting/IdentityServerMiddleware.cs:line 55
在duende.IdentityServer.hosting.mutualtlsendpointmiddleware.invoke(httpcontext上下文,iauthenticationschemeprovider schemes)in///src/indentityserityserver/sidentityserver/hosterver/hosting/mutualtlsendpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointpointmmiddleware.cselline 94
在microsoft.aspnetcore.authentication.authenticationmiddleware.invoke(httpcontext上下文)
上 在///src/sidentityServer/hosting/hosting/hosting/dynamedicproviders/dynamecproviders/dynamicicschemeschemeschemicschemicschemicschemicschemeachemeachemeateenticationmetple.cs-css in Duende.IdentityServer.hoster.hosting.Hosting.DynamicProviders.DynamicsCheMeAuthenticationmiddle.Invoke.Invoke(httpContext Context) 在microsoft.aspnetcore.cors.infrastructure.corsmiddle.g__invokecoreawaited | 15_0(httpcontext上下文,task`1 polighttask)
在duende.indeityserver.hosting.baseurlmiddleware.invoke(httpcontext上下文)中 在Microsoft.aspnetcore.diagnostics.developerexceptionpagemiddle.invoke(httpcontext上下文)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我检查了您的代码并发现了两个错误:
1,如果您使用的是Cookie Authentication,并设置为以下内容:
您需要修改您的代码如下:
2,您需要移动代码:
在您面前
可以修改代码并重试,如果您可以共享有关更多代码,我可以测试为您
更新:
尝试设置您的IdentityServer auth选项:
您可以关注文档:
I checked your codes and found two mistakes:
1,if you are using cookie authentication,and setted as below:
you need to modify your codes as below:
2,you need to move the codes:
in front of
You could modify your codes and try again,and if you could share more codes related,I could test for you
Update :
try to set your IdentityServer Auth Options:
You could follow the document:
http://docs.identityserver.io/en/latest/reference/options.html#authentication