public string GenerateTokenForUser(ReceivedUserDTO receivedExistingUserDTO) { var tokenEngine = new GenerateTokenEngine(_configuration); var tokenString = tokenEngine.GenerateTokenString(receivedExistingUserDTO); return(tokenString); }
public string GenerateTokenString(ReceivedUserDTO receivedExistingUserDTO) { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_config.GetSection("AppSettings:Token").Value); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, receivedExistingUserDTO.Id.ToString()), new Claim(ClaimTypes.Name, receivedExistingUserDTO.Username) }), Expires = DateTime.Now.AddDays(1), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha512Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); return(tokenString); }