If you need lifetime of token less than 5 mins, add ClockSkew property in Startup.cs:
vartokenValidationParameters=newTokenValidationParameters{ValidateIssuerSigningKey=true,IssuerSigningKey=newSymmetricSecurityKey(key),ValidateIssuer=false,ValidateAudience=false,ValidateLifetime=true,RequireExpirationTime=false,// Allow to use seconds for expiration of token// Required only when token lifetime less than 5 minutes// THIS ONEClockSkew=TimeSpan.Zero};
Don't forget to use UTC instead of local time. You will need to fix method GenerateJwtToken:
varrefreshToken=newRefreshToken(){JwtId=token.Id,IsUsed=false,UserId=user.Id,AddedDate=DateTime.UtcNow,// INVALID DATE, USE UTC// ExpiryDate = DateTime.Now.AddYears(1),// Now it's correctExpiryDate=DateTime.UtcNow.AddYears(1),IsRevoked=false,Token=RandomString(25)+Guid.NewGuid()};
Some fixes for the article:
If you need lifetime of token less than 5 mins, add
ClockSkew
property inStartup.cs
:Don't forget to use UTC instead of local time. You will need to fix method
GenerateJwtToken
:Thanks a lot Grand for these fixes, I am planning to add them this week.
If you want you can add a PR on the GitHub repo and I will merge them t