【问题标题】:is there some configuration wrong in IndentityServer4 configuration?IndentityServer4 配置中是否有一些配置错误?
【发布时间】:2019-05-24 18:00:17
【问题描述】:

同意页面不断重定向回 Indentityserver4 asp.net core 2.2 中的登录页面

我在 Identityservice 和 MVC 客户端上尝试了不同的配置,但没有成功

我已将代码上传到 github 的以下 url https://github.com/Dheerajmentor/IdentityServer4-Problem

MVC 客户端启动

public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            services.AddAuthentication(options => {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc";
            })
             .AddCookie("Cookie")
             .AddOpenIdConnect("oidc",options=> {
                 options.Authority = "https://localhost:44398/";
                 options.RequireHttpsMetadata = false;
                 options.ClientId = "mvc";
                 options.SaveTokens = true;
             });
        }

// 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();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseAuthentication();
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseCookiePolicy();

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

身份服务器启动

public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddIdentityServer()
                .AddInMemoryClients(APPConfigure.GetClients())
                .AddInMemoryIdentityResources(APPConfigure.GetIdentityResource())
                .AddInMemoryApiResources(APPConfigure.GetAPIResources())
                .AddTestUsers(APPConfigure.GetUsers())
                .AddDeveloperSigningCredential();


        }

我预计在成功登录后它会重定向到同意。

【问题讨论】:

    标签: asp.net-core identityserver4


    【解决方案1】:

    试着把 app.UseHttpsRedirection();在其他部分 app.UseHttpsRedirection() 确保您始终被重定向到 https 并且在开发中您在 http 上运行。

    if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                    app.UseHsts();
                    app.UseHttpsRedirection()
                }
                app.UseAuthentication();
    

    【讨论】:

      【解决方案2】:

      我刚刚遇到了类似的问题。我正在使用 https 以调试模式运行。删除 app.UseHttpsRedirection();为我工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-25
        • 1970-01-01
        • 2022-01-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多