I utilize ASP.NET Core 2.1.1
It is interesting that the expiration time is only being taken into account when one provides both ClockSkew
- in Startup.cs and JwtSecurityTokenHandler.TokenLifetimeInMinutes
- in a controller.
For instance:
services
.AddJwtBearer(x =>
{
...
x.TokenValidationParameters = new TokenValidationParameters()
{
ClockSkew = TimeSpan.FromMinutes(90),
...
plus
...
public async Task<AuthenticateOutput> Authenticate([FromBody] AuthenticateInput input)
{
var tokenHandler = new JwtSecurityTokenHandler();
tokenHandler.TokenLifetimeInMinutes = (int)TimeSpan.FromMinutes(90).TotalMinutes;
...
If I remove tokenHandler.TokenLifetimeInMinutes = (int)TimeSpan.FromMinutes(90).TotalMinutes;
part - the default expiration time is used.
It seems to me that tokenHandler.TokenLifetimeInMinutes
is still redundant and I just misunderstand the concept of how to set the expiration time correctly.
I also tried adding expiration claim - new Claim(ClaimTypes.Expiration, ...)
- but that didn't have much effect.