【发布时间】:2020-10-16 02:52:42
【问题描述】:
我是身份服务器 (IS4) 和身份验证/授权的新手。我正在玩一些场景客户端应用程序是.netcore 3.1(asp),IDP是IS4,版本3.1.3。我目前正在尝试的是:
- 用户尝试访问需要身份验证的客户端应用程序区域
- 用户将根据 IDP 输入他的凭据
- 用户将被重定向到客户端应用程序,现在可以访问
- 用户处于非活动状态 15 分钟
- 当用户尝试访问客户端应用程序上的同一区域时,他需要重新输入凭据
我无法使它工作的部分是最后一个,强制用户重新输入凭据。我正在使用选项“options.ExpireTimeSpan”(cookie 选项)和“UseTokenLifetime”(openidconnect 选项) 在客户端和 IDP 中客户端配置中的“IdentityTokenLifetime”和“AccessTokenLifetime”。
请注意,虽然我的要求是 15 分钟,但我在下面的代码 sn-ps 中尝试了 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())
}
}
【问题讨论】:
-
请注意,只要 IdentityServer 上的 cookie 有效,使用 SSO 用户就会自动登录。设置prompt=login 绕过SSO。
标签: c# .net-core identityserver4 openid-connect