【问题标题】:User to be forced to reenter credentials after 15 minutes15 分钟后强制用户重新输入凭据
【发布时间】: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


【解决方案1】:

我发现了一个他们回答相同问题的 SO 问题: IdentityServer4 Force User to re-enter credentials

虽然现在我意识到了一些事情,但如果我不添加强制重新输入凭据的建议解决方案(提示 = 登录)。在我的场景中,我没有启用离线访问。所以我不明白为什么我不断获得具有新到期时间的新令牌(exp)

【讨论】:

  • 当令牌过期时,您的用户将被重定向到身份提供者 - 身份提供者通过其 cookie 和策略知道您是谁,因此只需发布新令牌。我遇到了类似的情况,我相信解决这个问题的最好方法是在身份提供者中,但由于它超出了我们的管辖范围,我们不得不接受见证标记方法。在登录时,我们添加最后一次身份验证时间的声明,然后在需要重新身份验证的资源的策略中检查这一点,如果登录时间 > X 分钟,则强制提示=登录。不理想,但适用于我们的场景。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-30
  • 2017-07-08
  • 1970-01-01
  • 2022-01-15
  • 1970-01-01
相关资源
最近更新 更多