Reputation: 461
I am doing authentication using Jwt Security Token.
var token = new JwtSecurityToken(
issuer: "mysite.com",
audience: "mysite.com",
notBefore: DateTime.Now,
expires: DateTime.Now.AddDays(1),
claims: claimsdata,
signingCredentials: signInCred
);
startup.cs
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateIssuerSigningKey = true,
ValidIssuer = "mysite.com",
ValidAudience = "mysite.com",
ClockSkew=TimeSpan.Zero,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("mykey"))
};
});
but when I am debugging this code I got following time
But Now my PC time is 12:58 PM ....
Please help me to give correct expiry timing to token..
Upvotes: 0
Views: 1897
Reputation: 461
I implemented following snippet which solved my query...
var date = DateTime.Now.ToString();
DateTime convertedDate = DateTime.SpecifyKind(
DateTime.Parse(date),
DateTimeKind.Utc);
DateTime dt = convertedDate.ToLocalTime();
Upvotes: 0
Reputation: 78
Datetime.Now in JWT return the UTC time. that's why you can't get local time. If you want to change to local time , try to change the UTC time to your local time.
Upvotes: 3