Refresh api token

This commit is contained in:
2023-01-08 18:19:49 +01:00
parent c81a8297b7
commit 44ca2401e0
8 changed files with 30 additions and 16 deletions

View File

@@ -47,7 +47,7 @@ namespace WebAPI.Controllers
private dynamic JWTGenerator(User user)
{
var key = Encoding.ASCII.GetBytes(configuration.GetValue<string>("Secret"));
var expirationTime = DateTime.UtcNow.AddMinutes(30);
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new[]
@@ -57,7 +57,7 @@ namespace WebAPI.Controllers
new Claim(JwtRegisteredClaimNames.Jti,
Guid.NewGuid().ToString())
}),
Expires = DateTime.UtcNow.AddMinutes(30), // TODO: to long - to fix in the future
Expires = expirationTime,
SigningCredentials = new SigningCredentials
(new SymmetricSecurityKey(key),
SecurityAlgorithms.HmacSha512Signature)
@@ -66,7 +66,7 @@ namespace WebAPI.Controllers
var token = tokenHandler.CreateToken(tokenDescriptor);
var jwtToken = tokenHandler.WriteToken(token);
var stringToken = tokenHandler.WriteToken(token);
return new { token = stringToken, id = user.Id };
return new { token = stringToken, id = user.Id, expirationTime };
}
}
}