S
Soleyne1
Guest
Hi,
I create a project which need session tokens. User who is in the application connect with an authentication key after that for any module he wants to use, I will have a token, this token have an expiration date of 5 minutes for exemple and if there is no error have to be refresh.
I start to code something but I don't understand how to use JwtSecurityToken and i'm new in c#.
private string GenerateToken()
{
SymmetricSecurityKey key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("ijustwanttotestsomething"));
Claim[] claims = new Claim[]
{
new Claim(ClaimTypes.Name , "test")
};
JwtSecurityToken jwt = new JwtSecurityToken(
issuer : "Blinkingcaret",
audience : "Everyone",
claims : claims,
notBefore : DateTime.UtcNow,
expires : DateTime.UtcNow.AddMinutes(1),
signingCredentials : new SigningCredentials(key, SecurityAlgorithms.HmacSha256)
);
return new JwtSecurityTokenHandler().WriteToken(jwt);
}
[HttpPost]
public ActionResult<string> Create()
{
return GenerateToken();
}
Can i have help to implement expiration and refresh in my project please ?
Continue reading...
I create a project which need session tokens. User who is in the application connect with an authentication key after that for any module he wants to use, I will have a token, this token have an expiration date of 5 minutes for exemple and if there is no error have to be refresh.
I start to code something but I don't understand how to use JwtSecurityToken and i'm new in c#.
private string GenerateToken()
{
SymmetricSecurityKey key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("ijustwanttotestsomething"));
Claim[] claims = new Claim[]
{
new Claim(ClaimTypes.Name , "test")
};
JwtSecurityToken jwt = new JwtSecurityToken(
issuer : "Blinkingcaret",
audience : "Everyone",
claims : claims,
notBefore : DateTime.UtcNow,
expires : DateTime.UtcNow.AddMinutes(1),
signingCredentials : new SigningCredentials(key, SecurityAlgorithms.HmacSha256)
);
return new JwtSecurityTokenHandler().WriteToken(jwt);
}
[HttpPost]
public ActionResult<string> Create()
{
return GenerateToken();
}
Can i have help to implement expiration and refresh in my project please ?
Continue reading...