gpt4 book ai didi

identityserver4 - 在ASP.NET Core 2.0中使用IdentityServer4时出现无限身份验证循环

转载 作者:行者123 更新时间:2023-12-03 16:06:50 24 4
gpt4 key购买 nike

我有一个使用identityserver4框架的Identity Server,其URL为http://localhost:9000

我的Web应用程序是asp.net core 2.0,其URL是http://localhost:60002。该应用程序将使用Identity Server的登录页面。

我要登录后,Identity Server将重定向到应用程序页面(http://localhost:60002)

这是客户端应用程序的Startup.cs

Startup.cs

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

private string AuthorityUri => Configuration.GetValue<string>("UserManagement-Authority");

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = AuthorityUri; // "http://localhost:9000"
options.RequireHttpsMetadata = false;
options.ClientId = "customer.api";
options.ClientSecret = "testsecret";
options.ResponseType = "code id_token";
options.Scope.Add("customerprivatelinesvn.api");
options.Scope.Add("offline_access");
options.GetClaimsFromUserInfoEndpoint = true;
options.SaveTokens = true;
});

services.AddMvc();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true
});
}
else
{
app.UseExceptionHandler("/Home/Error");
}

app.UseStaticFiles();

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");

routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
}
}


这是Identity Server上的登录页面

enter image description here

但是存在一个无限循环,该循环调用http://localhost:9000/connect/authorize端点,然后通过“错误请求-请求太长”返回到http://localhost:60002/signin-oidc,如下所示。

当我查看cookie时,有很多项目“.AspNetCore.Correlation.OpenIdConnect.xxx”
enter image description here

这是Identiy服务器上的日志。它说Identiy.Application已成功通过身份验证。
enter image description here

有人知道这个问题是什么吗?以及如何解决这个问题?非常感谢你。

此致,

凯文

最佳答案

从现有的.NET Core 2.2项目复制启动代码并在新的.NET Core 3.1项目中重复使用启动代码之后,我也遇到了登录循环。

这里的问题是,必须在新的app.UseAuthorization();之前调用app.UseAuthentication();

https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#migrate-startupconfigure

只有在有人也遇到这个问题的情况下...

关于identityserver4 - 在ASP.NET Core 2.0中使用IdentityServer4时出现无限身份验证循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47100607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com