我目前正在使用ASP.NET核心身份。我無法弄清楚延長會話長度的設置,但我一直在註銷 - 我假設有一個大約20分鐘的失效時間,但我找不到該設置。請注意,我將Google用作外部OAuth。ASP.NET核心身份到期(谷歌OAuth)
services.AddIdentity<ApplicationUser, IdentityRole>(o =>
{
o.Password.RequireDigit = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonAlphanumeric = false;
o.Password.RequiredLength = 6;
o.SecurityStampValidationInterval = TimeSpan.FromHours(8);
o.Cookies.ExternalCookie.ExpireTimeSpan = TimeSpan.FromHours(8);
o.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromHours(8);
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
app.UseIdentityServer();
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = $"http://localhost:55504/",
RequireHttpsMetadata = false,
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"name",
"given_name",
"family_name",
"role"
}
});
var googleOptions = serviceProvider.GetRequiredService<GoogleOptions>();
app.UseGoogleAuthentication(new GoogleOptions
{
AuthenticationScheme = "Google",
SignInScheme = "Identity.External",
ClientId = googleOptions.ClientId,
ClientSecret = googleOptions.ClientSecret
});
可能的複製[Cookie身份驗證在ASP.NET Core中過期過早](https://stackoverflow.com/questions/45595615/c ookie-authentication-expiring-too-soon-in-asp-net-core) – SteelToe
你在哪裏以及如何託管你的應用程序? IIS? Azure應用服務?然後,您需要啓用數據保護,因此您的Cookie的加密密鑰在應用程序重新啓動後仍然存在。請參閱[我的答案](https://stackoverflow.com/a/47559544/455493) – Tseng