【发布时间】:2020-03-27 03:20:29
【问题描述】:
我用 IdentityServer4 创建了一个令牌我复制了这个 example 我只是修改了这个
在 IdentityServer -> 配置
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "client",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedScopes = { "tbtsmth" },
AccessTokenLifetime = 10,
IdentityTokenLifetime = 10
}
};
}
我的令牌应该在 10 秒后过期,每 10 秒我有一个刷新令牌,但我不知道如何测试它。我做这样的事情:
var tokenHandler = new JwtSecurityTokenHandler();
var jwtSecurityToken = tokenHandler.ReadJwtToken(tokenResponse.AccessToken);
Thread.Sleep(10000);
if (jwtSecurityToken.ValidTo < DateTime.UtcNow)
Console.WriteLine("expired");
else
Console.WriteLine("not expired");
它返回我已过期我认为它应该返回我未过期,因为它将被刷新。
【问题讨论】:
-
您可能想要(至少)更改标题。现在看来您要问same question 两次。
标签: c# token identityserver4