我已经阅读 IdentityServer4 问题线程大约一天了,但我仍然对会话/登录 cookie 过期感到困惑。
如果我像这样从客户端设置 cookie 过期(我使用 IdentityServer3 客户端和 IdentityServer4 服务器,以便启用 ASP.NET 4.x webapps 进行身份验证):
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
ExpireTimeSpan = new TimeSpan(10, 0, 0),
SlidingExpiration = true
});
Run Code Online (Sandbox Code Playgroud)
我可以打开 Chrome 开发人员工具 (F12) 并查看 cookie,并看到它们在浏览器关闭后立即过期(IdentityServer 的所有 cookie 的过期日期都设置为过期“1969-12-31T23:59: 59.000Z”,换言之,客户端未过期)。
无论我是否将客户端和服务器身份验证选项 UseTokenLifetime 都设置为 true,情况都是如此:
客户端:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
...
UseTokenLifetime = true,
...
Run Code Online (Sandbox Code Playgroud)
服务器端:
services.AddAuthentication()
.AddOpenIdConnect("MyLoginScheme", "A login scheme", options =>
...
options.UseTokenLifetime = true;
...
Run Code Online (Sandbox Code Playgroud)
我不确定如何让它占用我设置的客户端 cookie 生命周期。
我使用ASP.NET核心与Identity Server和Open标识连接所描述这里。设置“记住我”选项时(默认为 14 天),我需要更改身份验证 cookie 的过期时间。我可以看到名为“.AspNetCore.Identity.Application”的 cookie 对此负责。我正在尝试像这样设置到期时间:
.AddCookie(options =>
{
options.Cookie.Expiration = TimeSpan.FromDays(1);
options.ExpireTimeSpan = TimeSpan.FromDays(1);
})
Run Code Online (Sandbox Code Playgroud)
但它会影响另一个名为“.AspNetCore.Cookies”(包含相同的令牌值)的 cookie,它具有 Session 过期时间并且似乎没有做任何事情。我发现的所有更改过期时间的方法都只修改了“.AspNetCore.Cookies”cookie,我找不到任何修改“.AspNetCore.Identity.Application”cookie 的方法。(顺便说一句,services.ConfigureApplicationCookie某种原因,我根本没有触发方法)。
谁能解释一下这两个 cookie 之间的区别,以及如何修改“.AspNetCore.Identity.Application”过期时间?
我的代码 Startup.ConfigureServices
services.AddMvc(options =>
{
// ...
})
services.AddAuthorization(options =>
{
options.AddPolicy(PolicyNames.UserPolicy, policyBuilder =>
{
// ...
});
});
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "oidc";
})
.AddCookie(options =>
{
options.AccessDeniedPath = "/AccessDenied";
options.SlidingExpiration = true;
})
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = "<authority>"; …Run Code Online (Sandbox Code Playgroud) authentication asp.net-identity openid-connect asp.net-core identityserver4
Hej社区,
我被卡住了,我需要一些建议或指向解决方案的指针。我有一个相当简单的 Identity Server 4 设置:
我想在 10 分钟不活动后自动注销用户。在下面的示例中,我使用了 10 秒来加快测试速度。身份验证、重定向和用户强制注销按预期工作,就像使用下面的代码一样。但是,当用户空闲时间超过设定的 10 s 时,用户仍处于登录状态,不会重定向到 IDS 主机上的登录页面。
MVC 客户端使用 Hybrid Grant 设置为:
客户定义
var mvcClient = new Client
{
ClientId = "account-mvc",
ClientName = "Account MVC",
ClientUri = "https://localhost:5002",
AllowedGrantTypes = GrantTypes.Hybrid,
ClientSecrets = { new Secret("secret".Sha256()) },
EnableLocalLogin = true,
RequireConsent = false,
AllowOfflineAccess = false,
AccessTokenLifetime = 10, // 10 s by intention
IdentityTokenLifetime = 10, // 10 s by …Run Code Online (Sandbox Code Playgroud)