我很确定我错过了一些配置。
我正在使用Identity Server 4
使用ASP.NET核心1.0网站测试一个新的应用程序,其中混合流程配置如下。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
Authority = "https://account.testsite.com",
RequireHttpsMetadata = true,
ClientId = "superId",
ClientSecret = "supersecretclient",
ResponseType = "code id_token",
Scope = { "api1", "offline_access", "profile", "openid" },
GetClaimsFromUserInfoEndpoint = true,
SaveTokens = true,
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name",
RoleClaimType = "role"
}
});
用户在20分钟后不断登出,无论他们在网站上的活动如何。
IdSrv4的客户端配置如下:
Absolute refresh time: 2592000
Access token lifetime: 3600
Authorization code lifetime: 300
Identity token lifetime: 300
Sliding refresh token lifetime: 1296000
如果用户在页面上点击刷新,他会立即自动重新登录,但页面的自动加载功能会失败。
答案 0 :(得分:0)
我没有尝试使用官方ASP身份功能集,但我正在使用Cookie实施第三方登录。
Cookie身份验证方法有多种可用选项。我的例子来自我目前的申请。关键点是SlidingExpiration
和ExpireTimeSpan
app.UseCookieAuthentication(new CookieAuthenticationOptions() {
CookieName = "Company.MyApp.Web." + env.EnvironmentName.ToLower(),
AuthenticationScheme = "MyAppCookieAuth",
LoginPath = new PathString("/Home/Login/"),
AccessDeniedPath = new PathString("/Home/AccessDenied/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true,
ExpireTimeSpan = TimeSpan.FromHours(2),
SlidingExpiration = true
});
因此,当Cookie过半时,在下一页请求它将被刷新。这可能有助于持续登录更长时间。
有关Cookie身份验证的更多信息:
使用没有ASP.NET核心身份的Cookie中间件 - https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie
身份简介(包含与cookie相关的部分) - https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity