public string GenerateTokenForUser(ReceivedExistingUserDTO receivedExistingUserDTO) { var tokenEngine = new GenerateTokenEngine(_configuration); var token = tokenEngine.GenerateTokenString(receivedExistingUserDTO); return(token); }
public string GenerateTokenString(ReceivedExistingUserDTO receivedExistingUserDTO) { var tokenHandler = new JwtSecurityTokenHandler(); //v-- TODO: Add private in appsettings.json 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), // <---Note the key. SecurityAlgorithms.HmacSha512Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); return(tokenString); }