首页 > 解决方案 > 15 分钟后强制用户重新输入凭据

问题描述

我是身份服务器(IS4)和身份验证/授权的新手。我正在玩一些场景客户端应用程序是.netcore 3.1(asp),IDP是IS4,版本3.1.3。我目前正在尝试的是:

我无法使其工作的部分是最后一个,强制用户重新输入凭据。我正在使用选项“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())
                    }
                 }

标签: c#.net-coreidentityserver4openid-connect

解决方案


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

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


推荐阅读