c# - 15 分钟后强制用户重新输入凭据
问题描述
我是身份服务器(IS4)和身份验证/授权的新手。我正在玩一些场景客户端应用程序是.netcore 3.1(asp),IDP是IS4,版本3.1.3。我目前正在尝试的是:
- 用户尝试访问需要身份验证的客户端应用程序区域
- 用户将根据 IDP 输入他的凭据
- 用户将被重定向到客户端应用程序,现在可以访问
- 用户处于非活动状态 15 分钟
- 当用户尝试访问客户端应用程序上的同一区域时,他需要重新输入凭据
我无法使其工作的部分是最后一个,强制用户重新输入凭据。我正在使用选项“options.ExpireTimeSpan”(cookie 选项)和“UseTokenLifetime”(openidconnect 选项)客户端和 IDP 中客户端配置中的“IdentityTokenLifetime”和“AccessTokenLifetime”。
请注意,虽然我的要求是 15 分钟,但我在下面的代码片段中尝试了 1 分钟,只是为了能够快速测试它。
我在客户端应用程序中的设置:
services.AddAuthentication(options =>
{
options.DefaultScheme =CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(1);
})
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = "https://localhost:46318";
options.ClientId = "Confidential Client Id";
options.ResponseType = "code";
options.RequireHttpsMetadata = false;
options.UsePkce = true;
options.UseTokenLifetime = true;
options.CallbackPath = new PathString("/mycallbackendpoint");
options.SignedOutCallbackPath = new PathString("/mycallbackforsignoutendpoint");
options.Scope.Clear();
options.Scope.Add("openid");
options.Scope.Add("profile");
options.SaveTokens = true;
options.ClaimActions.MapAll();
options.ClientSecret = "Confidential Client Secret";
});
在 IS4 中,我有一个这样配置的客户端:
new Client
{
IdentityTokenLifetime = 60,
AccessTokenLifetime = 60,
AlwaysIncludeUserClaimsInIdToken = true,
ClientName = "Confidential Client",
ClientId = "Confidential Client Id",
AllowedGrantTypes = GrantTypes.Code,
ClientUri = "http://localhost:47331",
RequireConsent = false,
RequirePkce = true,
RedirectUris = new List<string>()
{
"http://localhost:47331/mycallbackendpoint"
},
PostLogoutRedirectUris = new List<string>()
{
"http://localhost:47331/mycallbackforsignoutendpoint"
},
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile
},
ClientSecrets =
{
new Secret("Confidential Client Secret".Sha256())
}
}
解决方案
我发现了一个他们回答相同问题的问题: IdentityServer4 Force User to re-enter credentials
虽然现在我意识到了一些事情,但如果我不添加强制重新输入凭据的建议解决方案(提示 = 登录)。在我的场景中,我没有启用离线访问。所以我不明白为什么我不断获得具有新到期时间的新令牌(exp)
推荐阅读
- javascript - 如何在拖放示例中获取已删除项目的对象?
- excel - Excel:如何在开始计算时显示对话框并在最后隐藏?
- javascript - 如何从反应 js 中的 map 方法中仅访问一项
- python - 当我从 php myadmin 导入数据库时,在 spyder ide 中出现错误 no module named 'mysql'
- python - 将 PyCharm Python 解释器设置为 Docker
- javascript - How to send SMS to a number stored in a JSON file?
- javascript - 增加 msg.payload[i] 变量
- algorithm - 找到将不同颜色的球分组的多种方法的算法
- swift - 如何在 Swift 导航栏的中心添加自定义按钮
- javascript - Node.JS 文件记录