【发布时间】:2019-07-02 18:29:21
【问题描述】:
Hej 社区,
我被困住了,我需要一些建议或指向解决方案的指针。我有一个相当简单的 Identity Server 4 设置:
- 具有 ASP.NET 身份的身份服务器 4
- ASP.NET Core 2.2 MVC 客户端
我想在用户闲置 10 分钟后自动注销。在下面的示例中,我使用了 10 秒来加快测试速度。身份验证、重定向和用户强制注销按预期工作,就像使用下面的代码的魅力一样。但是,当用户空闲时间超过设定的 10 秒时,用户仍然处于登录状态,不会重定向到 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 intention
RedirectUris = "https://localhost:5002/signin-oidc",
PostLogoutRedirectUris = "https://localhost:5002/signout-callback-oidc",
FrontChannelLogoutUri = "https://localhost:5002/signout-oidc",
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
},
};
身份服务器选项
services.AddIdentityServer(options =>
{
options.Authentication.CheckSessionCookieName = "auth-cookie";
options.Authentication.CookieLifetime = new System.TimeSpan(0, 0, 10);
options.Authentication.CookieSlidingExpiration = false;
options.Csp.Level = IdentityServer4.Models.CspLevel.Two;
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
})
.Add... // Left out for brevity
在 MVC 客户端的启动中我添加:
MVC 客户端启动
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies", options =>
{
options.ExpireTimeSpan = TimeSpan.FromSeconds(10);
options.SlidingExpiration = false;
options.Cookie.Name = "mvc-cookie";
})
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = "https://localhost:5001/";
options.ClientId = "account-mvc";
options.ClientSecret = "secret";
options.ResponseType = "code id_token";
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
});
并在Configure 方法中添加了app.UseAuthentication()。
问题
一旦会话超时,如何确保用户在身份服务器上退出?任何提示和帮助表示赞赏!
【问题讨论】:
-
请检查这个答案 - stackoverflow.com/questions/49367156/…
标签: c# asp.net-core .net-core identityserver4 openid-connect