private async Task ValidarUsuario(OAuthGrantResourceOwnerCredentialsContext context, ClaimsIdentity identity) { var usuario = await _userManager.FindAsync(context.UserName, context.Password); if (usuario == null) { context.SetError("no_permiso", "El Email o password son incorrectos."); _esError = true; return; } var authManager = context.OwinContext.Authentication; var user = await _userManager.FindAsync(usuario.Email, context.Password); await _userManager.SignInAsync(authManager, user, isPersistent : false); var userRoles = context.OwinContext.Authentication.AuthenticationResponseGrant.Identity.Claims.Where(c => c.Type == ClaimTypes.Role) .Select(c => c.Value) .ToList(); await EstablecerRoles(identity, userRoles); identity.AddClaim(new Claim("UsuarioId", usuario.Id.ToString())); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName.ToLower())); }
public async Task <IHttpActionResult> Post([FromBody] LoginViewModel model) { var contadorAction = this.ActionContext.ActionArguments.Count; if (ModelState.IsValid) { var user = await _userManager.FindAsync(model.Email, model.Password); if (user != null) { //await _userManager.SignInAsync(AuthenticationManager, user, model.RememberMe); //return RedirectToLocal(returnUrl); } else { ModelState.AddModelError("", "Invalid username or password."); } } // If we got this far, something failed, redisplay form return(Ok(model)); }