我试图将我的隐式客户端的AccessTokenLifetime属性设置为90秒 . 客户端是一个JavaScript应用程序 .
但是,在令牌过期后,客户端仍然可以在大约5分钟内访问api范围“api1” .
这是IdentityServer4中客户端配置的代码:
// JavaScript Client
new Client
{
ClientId = "js",
ClientName = "JavaScript Client",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RedirectUris = { "http://localhost:5003/callback.html" },
PostLogoutRedirectUris = { "http://localhost:5003/index.html" },
AllowedCorsOrigins = { "http://localhost:5003" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"api1"
},
AccessTokenLifetime = 90
}
我在这里使用来自IdentityServer github repo的Javascript快速入门解决方案https://github.com/IdentityServer/IdentityServer4.Samples/tree/release/Quickstarts/7_JavaScriptClient
1 回答
Microsoft JWT验证中间件中存在时钟偏差 . 它默认设置为5分钟,不能少于 . 否则 - 访问令牌的建议生命周期为
as short as possible
. 特别是在客户端客户端,您将其暴露给浏览器 . 所以你最好的解决方案 - 保留默认值(300秒/ 5分钟) .检查this topic - 对此有一个很好的讨论 .