IdentityServer4仅与HTTPS一起使用

时间:2020-11-08 14:57:09

标签: identityserver4

我正在从Identity Server 3迁移到4。 我在本地开发环境中运行没有HTTPS的Identity Server 4时遇到问题。 使用HTTPS-一切正常。没有它,用户将无法通过身份验证,而只能重定向 到登录页面。 Cookie未设置。

我知道Identity Server 3曾经具有RequireSsl选项,该选项现在不存在了。 我已经搜索了几个小时的文档,但一无所获。

我正在使用IdentityServer4 4.1.1和AspNet Core 3.1 我的Startup.cs看起来像这样:

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityServer()
                .AddInMemoryClients(Clients.Get())
                .AddInMemoryIdentityResources(Configs.Resources.GetIdentityResources())
                .AddInMemoryApiResources(Configs.Resources.GetApiResources())
                .AddInMemoryApiScopes(Configs.Resources.GetApiScopes())
                .AddTestUsers(Users.Get())
                ..AddDeveloperSigningCredential();

            services.AddControllersWithViews();

            services.AddMvc(options => options.EnableEndpointRouting = false);
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseRouting();

            app.UseIdentityServer();
            app.UseAuthorization();

            app.UseEndpoints(endpoints => endpoints.MapControllers());

            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
        }

我想念什么?

1 个答案:

答案 0 :(得分:0)

我想,您可以在Chrome浏览器中尝试一下。当您打开开发人员控制台(F12)时,很可能会发现警告SameSite=None cookie必须是安全的。

如果我的上述猜测是正确的,则可能有两种可能的原因:您使用了自定义的CookieAuthenticationOptions,在其中您明确设置了options.Cookie.SameSite = SameSiteMode.None(看着您没有看到的启动状态),或者是{{3} }对您的配置不利。

您可以按照以下方式进行调整:

services.AddIdentityServer(options =>
{
    options.Authentication.CookieSameSiteMode = SameSiteMode.Lax;
})

将在localhost上工作,将阻止对您IdSrv根域以外托管的客户端进行静默刷新。因此,您必须选择是将Lax用于生产还是仅用于家庭游乐场(但通常不建议在任何地方都不推荐)。