/// <summary> /// Post API/Login /// </summary> /// <param name="User">User à tester</param> public IHttpActionResult Post(UserModel User) { if ((new[] { "Admin", "User", "Anonyme" }).Contains(ValidateTokenAndRole.ValidateAndGetRole(Request), StringComparer.OrdinalIgnoreCase)) { if (User == null || User.Password == null || User.Username == null) { return(BadRequest()); } else { if (repo.Check(User.Username, User.Password)) { UserEntity U = repo.GetOneByUsername(User.Username); JWTService jwt = new JWTService("FZeDfgPkyXaDFyMwQfSbIoJhF", "localhost:4200", "localhost:4200"); string token = jwt.Encode(U); return(Ok(token)); } else { return(BadRequest()); } } } else { return(Unauthorized()); } }
static void Main(string[] args) { JWTService service = new JWTService( "azertyuiopqsdfghjklm", "www.mondomaine.com", "www.domaine2.com" ); Utilisateur u = new Utilisateur() { Nom = "Andre", Id = 1, }; string token = service.Encode(u); Console.WriteLine(token); if (service.ValidateToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJZCI6IjEiLCJOYW1lIjoiS2h1biIsIkJpcnRoRGF0ZSI6IjA2LTA1LTgyIDAwOjAwOjAwIiwibmJmIjoxNTgzMTQwNzU3LCJleHAiOjE1ODMxNDA3NTgsImlzcyI6Ind3dy5tb25kb21haW5lLmNvbSIsImF1ZCI6Ind3dy5kb21haW5lMi5jb20ifQ.9-qqjWiJe_DzjDiXMA25rPY23VEwKMc8q2UPFDxLfWE")) { Console.WriteLine("OK"); } else { Console.WriteLine("KO"); } Console.ReadKey(); }
public IActionResult Get() { //if (HttpContext.Request.Path.ToUriComponent().Contains("localhost:4200")) //{ UserEntity U = new UserEntity(); U.Role = "Anonymous"; JWTService jwt = new JWTService("FZeDfgPkyXaDFyMwQfSbIoJhF", "localhost:4200", "localhost:4200"); string token = jwt.Encode(U); return(Ok(JsonConvert.SerializeObject(token))); //} //else return Unauthorized(); }
/// <summary> /// Post API/Login /// </summary> /// <param name="User">User à tester</param> public IHttpActionResult Get() { if (HttpContext.Current.Request.UrlReferrer.AbsoluteUri.Contains("http://localhost:4200/")) { UserEntity U = new UserEntity(); U.Role = "Anonymous"; JWTService jwt = new JWTService("FZeDfgPkyXaDFyMwQfSbIoJhF", "localhost:4200", "localhost:4200"); string token = jwt.Encode(U); return(Ok(token)); } else { return(Unauthorized()); } }
public IHttpActionResult Login(LoginModel model) { UserService s = new UserService(); User user = s.CheckUser(model.Username, model.Password); int id = user.UserId; if (id == 0) { return(Unauthorized()); } else { JWTService service = new JWTService( "dfjlkwdlsdjtiorxkbS&", "localhost", "postman" ); return(Ok(service.Encode(user))); } }
public IHttpActionResult Login(CompteUtilisateur model) { UtilisateurService us = new UtilisateurService(); int id = us.Check(model.NomUtilisateur, model.Password); if (id == 0) { return(Unauthorized()); } else { Utilisateur u = us.Get(id); JWTService service = new JWTService( "Tn!_bTZ&Gt^7LM&X!HxnTT6H", "localhost", "postman" ); return(Ok(service.Encode(u))); } }