public Out_ApiResponse RequestToken([FromBody] InLogin inLogin) { var claims = new[] { new Claim(ClaimTypes.Name, "Chou"), new Claim(ClaimTypes.Role, "User"), }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("this is a jwt key")); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken( issuer: "CoreJWT.vulcan.net", audience: "Core RESTful API", claims: claims, expires: DateTime.Now.AddMinutes(30), signingCredentials: creds); return(new Out_ApiResponse(HttpStatusCode.OK, new { access_token = new JwtSecurityTokenHandler().WriteToken(token), token_type = "Bearer", }, "")); }
public async Task <Out_ApiResponse> RequestCookie([FromBody] InLogin inLogin) { ClaimsIdentity identity = new ClaimsIdentity("myLogin"); identity.AddClaim(new Claim(ClaimTypes.Name, "Chou")); identity.AddClaim(new Claim(ClaimTypes.Role, "Admin")); identity.AddClaim(new Claim("Name", "周庭孝")); identity.AddClaim(new Claim("DEPOT", "TEST")); ClaimsPrincipal principal = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); string cookie = string.Empty; foreach (var headers in HttpContext.Response.Headers.Values) { foreach (var header in headers) { if (header.Contains("test")) { cookie = header; } } } return(new Out_ApiResponse(HttpStatusCode.OK, cookie, "")); }
public async Task <ActionResult <OutLogin> > Login(InLogin login) { var realizarLogin = await loginUser.Login(login); if (realizarLogin.Message != null) { return(BadRequest(realizarLogin)); } realizarLogin.Token = tokenService.GenerateToken(realizarLogin); return(realizarLogin); }
public ActionResult <Login> Login([FromBody] InLogin login) { try { List <User> users = Get(); Login log = _loginService.Login(login.Email, login.Password, users); if (log == null) { return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status406NotAcceptable)); } return(CreatedAtRoute("GetUser2", new { id = log.Id.ToString() }, log)); } catch (Exception e) { string message = e.Message; string stackTrace = e.StackTrace; return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError)); } }
public async Task <OutLogin> Login(InLogin user) { ValidarLogin(user); if (this.Invalid) { return new OutLogin { Message = this.Notifications } } ; var consultarLogin = await administradorRepository.Login(user.Usuario, user.Senha); if (consultarLogin is null) { return new OutLogin { Message = Messages.LOGIN_OU_SENHA_INCORRETOS } } ; return(mapper.Map <OutLogin>(consultarLogin)); }
private void ValidarLogin(InLogin user) { AddNotifications(new FluentValidator.Validation.ValidationContract().Requires() .IsNotNullOrEmpty(user.Usuario, "Login ou Senha", Messages.LOGIN_OU_SENHA_INCORRETOS) .IsNotNullOrEmpty(user.Senha, "Login ou Senha", Messages.LOGIN_OU_SENHA_INCORRETOS)); }