我正在使用IdentityServer4和MVC客户端。当客户端会话过期时,我希望我的用户被迫重新登录。但是,无论我做什么,IdentityServer似乎都会在会话结束时自动重新登录用户。
我的客户端启动代码如下(为了测试,会话时间设置为30秒)
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies", options => { options.ExpireTimeSpan = new TimeSpan(0, 0, 30); })
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = identityUrl;
options.RequireHttpsMetadata = false;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("Billing");
options.Scope.Add("offline_access");
options.UseTokenLifetime = false;
});
那么我在IdentityServer中的配置如下:
new Client
{
ClientId = "Test",
ClientName = "Test",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
AlwaysIncludeUserClaimsInIdToken = true,
RequireConsent = false,
IdentityTokenLifetime = 30,
AccessTokenLifetime = 30,
ClientSecrets =
{
new Secret("secret".Sha256())
},
RedirectUris = { billingUrl + "/signin-oidc" },
PostLogoutRedirectUris = { billingUrl + "/signout-callback-oidc" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"Billing",
"role",
"VisionBlue.Cloud.BillingAPI"
},
AllowOfflineAccess = true
},
使用 Fiddler 我可以看到在 30 秒后会向 IdentityServer 的 /connect/authorize 发送一个请求,这会自动让用户再次登录。
有什么想法吗?我已经将所有超时时间设为 30 秒进行测试。