public IActionResult Authenticate([FromBody] Models.AuthenticationModel authentication) { User user = new User { Id = 1, EmailAddress = "*****@*****.**", FirstName = "Matti", LastName = "Lindroth", Password = "******", Token = "", }; string secret = "CE055E57-6854-440B-A80C-03AC68ED5E9A"; // authentication successful so generate jwt token var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()) }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); user.Token = tokenHandler.WriteToken(token); return(Ok(user)); }
public Models.AuthenticationResponse StartSession(Models.AuthenticationModel model) { var response = new Models.AuthenticationResponse(); try { response.SessionId = DataAccess.Authentication.StartSession(model.ApplicationKey, model.UserName, model.Password, model.DeviceDescription); response.AuthenticationSuccesful = true; response.OperationSuccesful = true; } catch (Exception ex) { response.OperationSuccesful = false; response.ErrorMessage = ex.Message; response.ExceptionDetails = ex.ToString(); } return(response); }