首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.NET核心6标识服务器(duende):没有找到DefaultAuthenticateScheme,也没有在IdentityServerOptions上配置CookieAuthenticationScheme

ASP.NET核心6标识服务器(duende):没有找到DefaultAuthenticateScheme,也没有在IdentityServerOptions上配置CookieAuthenticationScheme
EN

Stack Overflow用户
提问于 2022-04-26 17:12:58
回答 1查看 2.7K关注 0票数 1

这是我们的装置。我们有

  • 角web应用程序
  • identity server API (ASP.NET Core 6,duende identity server)

Program.cs中的身份服务器配置

代码语言:javascript
复制
    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();

在那之后,我们打电话

代码语言:javascript
复制
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上下文中)

EN

回答 1

Stack Overflow用户

发布于 2022-04-27 06:23:23

我检查了你的密码,发现了两个错误:

1,如果使用cookie身份验证,并设置如下:

您需要修改代码如下:

代码语言:javascript
复制
    builder.Services.AddAuthentication(options => 
     {
        ......
     })
   .AddCookie( "Cookies",options =>
    {
        ......;
    })

2 .你需要移动密码:

代码语言:javascript
复制
app.useAuthentication();

在前面

代码语言:javascript
复制
app.useAuthorization(); 

您可以修改代码,然后再试一次,如果您可以共享更多相关代码,我可以为您进行测试。

更新:尝试设置您的IdentityServer Auth选项:

代码语言:javascript
复制
builder.Services
        .AddIdentityServer(options =>
        {
            ......
            options.Authentication.CookieAuthenticationScheme= ....
            options.Authentication.CookieLifetime = .....
            .....
        }); 

您可以跟随文档:http://docs.identityserver.io/en/latest/reference/options.html#authentication

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72017977

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档