public string MakeToken(CustomUSer user) { SigningCredentials signingCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Hello world from our api token")), SecurityAlgorithms.HmacSha256); List <Claim> claims = new List <Claim>() { new Claim(ClaimTypes.Email, user.Email), new Claim(ClaimTypes.Role, user.Role.ToString()) }; JwtSecurityToken jwt = new JwtSecurityToken(issuer: "utopios", audience: "utopios", claims: claims, signingCredentials: signingCredentials, expires: DateTime.Now.AddDays(10)); return(new JwtSecurityTokenHandler().WriteToken(jwt)); }
public IActionResult Login([FromBody] UserConnection user) { //logique métier de connexion, if (user.login == "ihab" && user.password == "123456") { CustomUSer customUser = new CustomUSer() { Email = "*****@*****.**", Role = Role.customer }; return(Ok(new { token = _generator.MakeToken(customUser) })); } return(NotFound()); }