IdentityServer4仅适用于HTTPS
我正在从Identity Server 3迁移到4。 在本地开发环境中运行没有HTTPS的Identity Server 4时遇到问题。 使用HTTPS-一切正常。如果没有它,用户将无法进行身份验证,而只是重定向 转到登录页面。cookie未设置 我知道Identity Server 3以前有RequireSsl选项,现在已经不存在了。 我查了几个小时的文件,但什么也没找到 我使用的是IdentityServer4 4.1.1和AspNet Core 3.1 我的Startup.cs如下所示:IdentityServer4仅适用于HTTPS,identityserver4,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();
}
我错过了什么?我想,你可以在Chrome上试试。当您打开开发控制台(F12)时,很可能会发现
SameSite=None
cookie必须是安全的警告
如果我以上的猜测是正确的,可能有两个原因:您使用定制的CookieAuthenticationOptions
,其中您显式设置了options.Cookie.SameSite=SameSiteMode.None
(查看您的启动情况,您不知道),或者不适合您的配置
您可以按如下方式对其进行调整:
services.AddIdentityServer(选项=>
{
options.Authentication.CookieSameSiteMode=SameSiteMode.Lax;
})
将在localhost上工作,将阻止IdSrv根域之外托管的客户端的静默刷新。因此,你必须选择是喜欢Lax用于制作,还是仅仅用于家庭游乐场(但一般来说,不建议在任何地方使用)。你是对的。我正在用Chrome试试。在MS Edge中尝试过,现在就可以了。不幸的是CookieAuthenticationOptions没有为Chrome修复它。我的错误。它起作用了!一定是没有重建它什么的。。今天的调整太多了。非常感谢你的帮助。我明白了,我必须阅读关于同一网站的全部内容。:)我建议在本地使用https并避免更改samesite,这将打破某些OIDC的情况,例如iframe-您可以在本地使用asp.net核心开发证书来进行https,并且设置@nahidf非常容易,我在回答中提到了这一点。无论如何,一般的做法应该是尽可能避免使用None,因为谷歌的计划根本不赞成它。当然,这必须是明智的决定。目前,在大多数情况下,没有一种方法是有效的,但情况变化很快,做好准备是很好的。