public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var user = codenationContext.Users.FirstOrDefault(x => x.Email == context.UserName);

            // verificar a senha
            if (user != null && user.Password.TrimEnd() == context.Password)
            {
                // retornar objeto tipo GrantValidationResult com sub, auth e claims
                context.Result = new GrantValidationResult(
                    subject: user.Id.ToString(),
                    authenticationMethod: "custom",
                    claims: UserProfileService.GetUserClaims(user)
                    );
                return(Task.CompletedTask);
            }
            else
            {
                context.Result = new GrantValidationResult(
                    TokenRequestErrors.InvalidGrant, "Usuário ou senha inválidos");

                return(Task.FromResult(context.Result));
            }
            context.Result = new GrantValidationResult(
                TokenRequestErrors.InvalidGrant, "Invalid username or password");
            return(Task.CompletedTask);
        }
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            //acessar context de user
            // var user = _context.Users.FirstOrDefault(X => X.Email == context.UserName);
            UserService userService = new UserService(_context);

            User user = userService.FindByEmail(context.UserName);

            //validar senha
            if (user != null && user.Password == context.Password)
            {
                //retornar objeto com propriedades GrantValidationResult - sub, auth e claims
                context.Result = new GrantValidationResult(
                    //subject: sempre passa o nome de usuario ou id.. algo que seja unique
                    subject: user.Id.ToString(),
                    "custom",
                    UserProfileService.GetUserClaims(user));  //aqui vai acessar a classe de validação

                return(Task.CompletedTask);
            }
            // add descrição de erro de token
            context.Result = new GrantValidationResult(
                TokenRequestErrors.InvalidGrant, "Invalid username or password");
            return(Task.FromResult(context.Result));
        }
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            context.Result = new GrantValidationResult(
                TokenRequestErrors.InvalidGrant, "Invalid username or password");

            if (_dbContext.Users.Any(x => x.Email == context.UserName && x.Password == context.Password))
            {
                var user = _dbContext.Users.FirstOrDefault(x => x.Email == context.UserName);

                context.Result = new GrantValidationResult(subject: user.Id.ToString(),
                                                           authenticationMethod: "custom",
                                                           claims: UserProfileService.GetUserClaims(user));
            }
            return(Task.CompletedTask);
        }
示例#4
0
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var user = _context.Users.FirstOrDefault(u => u.Email == context.UserName);

            var invalidUser = user == null || user.Password != context.Password;

            if (invalidUser)
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Invalid username or password");
                return(Task.CompletedTask);
            }

            var claims = UserProfileService.GetUserClaims(user);

            context.Result = new GrantValidationResult(user.Id.ToString(), "custom", claims);

            return(Task.CompletedTask);
        }
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var user = _context.Users.Where(x => x.Email.Equals(context.UserName) && x.Password.Equals(context.Password)).AsNoTracking().FirstOrDefault();

            if (user == null)
            {
                context.Result = new GrantValidationResult(
                    TokenRequestErrors.InvalidGrant, "Invalid username or password");
            }
            else
            {
                context.Result = new GrantValidationResult(
                    subject: user.Id.ToString(),
                    authenticationMethod: "custom",
                    claims: UserProfileService.GetUserClaims(user));
            }

            return(Task.CompletedTask);
        }
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var user = _context.Users.FirstOrDefault(x => x.Email == context.UserName);

            if (user != null && user.Password.TrimEnd() == context.Password)
            {
                context.Result = new GrantValidationResult(
                    subject: user.ToString(),
                    authenticationMethod: "custom",
                    claims: UserProfileService.GetUserClaims(user)
                    );
                return(Task.CompletedTask);
            }
            else
            {
                context.Result = new GrantValidationResult(
                    TokenRequestErrors.InvalidGrant, "Invalid username or password");
                return(Task.FromResult(context.Result));
            }
        }
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            UserService userService = new UserService(_context);

            User user = userService.FindByEmail(context.UserName);


            if (user != null && user.Password == context.Password)
            {
                context.Result = new GrantValidationResult(

                    subject: user.Id.ToString(),
                    "custom",
                    UserProfileService.GetUserClaims(user));

                return(Task.CompletedTask);
            }

            context.Result = new GrantValidationResult(
                TokenRequestErrors.InvalidGrant, "Invalid username or password");
            return(Task.FromResult(context.Result));
        }
示例#8
0
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            //Acessar contexto de cliente
            var user = _dbContext.Users.FirstOrDefault(x => x.Email == context.UserName);

            //validar a senha
            if (user != null && user.Password == context.Password)
            {
                //retornar o Grant Validation Result
                context.Result = new GrantValidationResult(
                    subject: user.Id.ToString(),
                    authenticationMethod: "custom",
                    claims: UserProfileService.GetUserClaims(user));
                return(Task.CompletedTask);
            }
            else
            {
                //add descrição de erro de token
                context.Result = new GrantValidationResult(
                    TokenRequestErrors.InvalidGrant, "Invalid username or password");
                return(Task.FromResult(context.Result));
            }
        }
示例#9
0
        //Valida o usuario, pra poder gerar o Token
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            //UserName = Email, conforme foi definido
            User user = FindUserByEmailAndPassword(email: context.UserName, password: context.Password);

            if (user == null)
            {
                context.Result = new GrantValidationResult(
                    error: TokenRequestErrors.InvalidGrant,
                    errorDescription: "Invalid username or password"
                    );
            }
            else
            {
                context.Result = new GrantValidationResult(
                    subject: user.Id.ToString(),                   //Subject = Identificação do usuario que esta autenticando
                    authenticationMethod: "custom",
                    claims: UserProfileService.GetUserClaims(user) //Claims= Informações do usuario -> No caso: Email e Role
                    );
            }

            return(Task.CompletedTask);
        }
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            User user = _codenationContext.Users.Where(users => users.Email == context.UserName && users.Password == context.Password).AsNoTracking().FirstOrDefault();

            if (user == null)
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Invalid username or password");
            }
            else
            {
                context.Result = new GrantValidationResult(user.Id.ToString(), "custom", UserProfileService.GetUserClaims(user));
            }

            return(Task.CompletedTask);
        }
示例#11
0
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            //_dbContext.Users.Where(x => x.Email == email).FirstOrDefault();
            //User userFind = _dbContext.Users.FirstOrDefault(user => user.Email == context.UserName && user.Password == context.Password);

            User userFind = _dbContext.Users.Where(x => x.Email == context.UserName).FirstOrDefault();

            if (userFind != null && userFind.Password == context.Password)
            {
                //if (userFind != null)
                context.Result = new GrantValidationResult(subject: userFind.Id.ToString(), authenticationMethod: "custom", claims: UserProfileService.GetUserClaims(userFind));
            }
            else
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Invalid username or password");
            }
            return(Task.CompletedTask);
        }
示例#12
0
        public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var user = await _dbContext.Users.FirstOrDefaultAsync(c => c.Email == context.UserName && c.Password == context.Password);

            if (user == null)
            {
                context.Result = new GrantValidationResult(
                    TokenRequestErrors.InvalidGrant, "Invalid username or password");
            }
            else
            {
                context.Result = new GrantValidationResult(user.Id.ToString(), "custom", UserProfileService.GetUserClaims(user));
            }
        }
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var user = dbContext.Users.Where(x => x.Email.Equals(context.UserName) && x.Password.Equals(context.Password)).FirstOrDefault();

            if (user == default)
            {
                context.Result = new GrantValidationResult(
                    TokenRequestErrors.InvalidGrant, "Invalid username or password");
                return(Task.CompletedTask);
            }

            var subject = user.Id.ToString();
            var authenticationMethod = "custom";

            context.Result = new GrantValidationResult(subject, authenticationMethod, UserProfileService.GetUserClaims(user));

            return(Task.CompletedTask);
        }