加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

在asp.net core 2.0中使用identityserver4时的无限认证循环

发布时间:2020-12-16 07:42:26 所属栏目:asp.Net 来源:网络整理
导读:我有一个使用identityserver4框架的Identity Server,它的url是 http://localhost:9000 我的Web应用程序是asp.net core 2.0,其URL是http://localhost:60002.此应用程序将使用Identity Server的登录页面. 我希望登录后,Identity Server将重定向到应用程序页面(
我有一个使用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,“Bad Request – Request Too Long”如下所示.

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

enter image description here

这是在Identiy Server上的日志.它说Identiy.Application已成功通过身份验证.

enter image description here

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

最好的祝福,

凯文

解决方法

好吧,您的Identity Server日志中显示了很长的请求 – 错误显示“错误请求 – 请求时间过长”.我猜这个问题是你的请求太大了:)
maximum length of HTTP GET request?

你试过发帖而不是使用GET吗?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读