kei*_*itn 3 c# asp.net-core-mvc identityserver4
我正在使用IdentityServer4和MVC客户端。当客户端会话期满时,我希望我的用户被迫再次登录。但是,无论我做什么,IdentityServer似乎都会在会话结束时自动将用户重新登录。
我在客户端的启动时间是(会话需要30秒才能测试)
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies", options => { options.ExpireTimeSpan = new TimeSpan(0, 0, 30); })
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = identityUrl;
options.RequireHttpsMetadata = false;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("Billing");
options.Scope.Add("offline_access");
options.UseTokenLifetime = false;
});
Run Code Online (Sandbox Code Playgroud)
然后我在IdentityServer中的配置如下:
new Client
{
ClientId = "Test",
ClientName = "Test",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
AlwaysIncludeUserClaimsInIdToken = true,
RequireConsent = false,
IdentityTokenLifetime = 30,
AccessTokenLifetime = 30,
ClientSecrets =
{
new Secret("secret".Sha256())
},
RedirectUris = { billingUrl + "/signin-oidc" },
PostLogoutRedirectUris = { billingUrl + "/signout-callback-oidc" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"Billing",
"role",
"VisionBlue.Cloud.BillingAPI"
},
AllowOfflineAccess = true
},
Run Code Online (Sandbox Code Playgroud)
使用小提琴手,我可以看到30秒后,请求已发送到IdentityServer上的/ connect / authorize,该服务器自动重新登录用户。
有任何想法吗?我已将所有超时设置为30秒作为测试。
Sco*_*ady 12
prompt=login在授权请求(https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest)上使用OpenID Connect参数。这将告诉IdentityServer您希望用户重新认证,而不是使用SSO或IdentityServer会话长度。
您应该可以在OpenIdConnectOptions中使用ASP.NET Core来做到这一点:
options.Events.OnRedirectToIdentityProvider = context =>
{
context.ProtocolMessage.Prompt = "login";
eturn Task.CompletedTask;
};
Run Code Online (Sandbox Code Playgroud)
不过,可能有一种更简单的方法来进行设置。
| 归档时间: |
|
| 查看次数: |
2520 次 |
| 最近记录: |