public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            UsuariosRepositorio user_repo = new UsuariosRepositorio();
            RolesRepositorio    rol_repo  = new RolesRepositorio();

            List <Rol>     roles = rol_repo.GetAll().ToList();
            List <Usuario> users = user_repo.GetAll().ToList();
            //var a = users.Where(x => x.UserName == context.UserName);

            Usuario user = users.Where(x => x.NombreUsuario == context.UserName && x.Contrasena == context.Password).SingleOrDefault();


            //Authenticate the user credentials
            if (user != null)

            {
                //identity.AddClaim(new Claim(ClaimTypes.Role, acc.GetUserRole(context.UserName)));
                Rol rol = roles.FirstOrDefault(x => x.Id == user.RolId);
                identity.AddClaim(new Claim("role", rol.NombreRol));
                identity.AddClaim(new Claim("username", context.UserName));
                identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
                context.Validated(identity);
            }
            else
            {
                context.SetError("invalid_grant", "Provided username and password is incorrect");
                return;
            }
        }
Beispiel #2
0
 public List <Rol> GetAll()
 {
     return(_rolesRepositorio.GetAll());
 }