【发布时间】:2018-12-23 01:11:43
【问题描述】:
我使用ASP.NET Core 2.1.1
有趣的是,只有在 both ClockSkew - 在 Startup.cs and 中才考虑过期时间JwtSecurityTokenHandler.TokenLifetimeInMinutes - 在控制器中。
例如:
services
.AddJwtBearer(x =>
{
...
x.TokenValidationParameters = new TokenValidationParameters()
{
ClockSkew = TimeSpan.FromMinutes(90),
...
加
...
public async Task<AuthenticateOutput> Authenticate([FromBody] AuthenticateInput input)
{
var tokenHandler = new JwtSecurityTokenHandler();
tokenHandler.TokenLifetimeInMinutes = (int)TimeSpan.FromMinutes(90).TotalMinutes;
...
如果我删除 tokenHandler.TokenLifetimeInMinutes = (int)TimeSpan.FromMinutes(90).TotalMinutes;
部分 - 使用默认过期时间。
在我看来tokenHandler.TokenLifetimeInMinutes仍然是多余的,我只是误解了如何正确设置过期时间的概念。
我也尝试添加过期声明 - new Claim(ClaimTypes.Expiration, ...) - 但效果不大。
【问题讨论】:
标签: c# authentication asp.net-core jwt token