I'm using JWT in my.Net Core application and I'm using System.IdentityModel.Tokens.Jwt (5.6.0) I'm trying to set the expiration time as follows:
var token = new JwtSecurityToken(
"www.site.com",
"www.site.com",
claims,
expires: DateTime.UtcNow.AddMinutes(5),
signingCredentials: credentials);
My computer's time is 2.38 pm and tokens validate to propertys' value is 9.43 pm. Which has to be 2.43 pm.
My Startup.cs configurations are as bellow:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ClockSkew = TimeSpan.Zero,
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Authentication:Issuer"],
ValidAudience = Configuration["Authentication:Issuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Authentication:Secret"]))
};
});
What is the reason for this? Thank you for your help.
You are living a location where the time zone is UTC -7. DateTime.UtcNow
returns UTC time, use DateTime.Now
instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.