Ejemplo n.º 1
0
        public async Task <IAuthenticationResponse> LogIn(object userData, string key)
        {
            var authData = JsonConvert.DeserializeObject <AuthData>(userData.ToString());

            //if (authData.SystemCode == 0) throw new Exception("Código do sistema não informado");
            if (authData.UserIdentity == null)
            {
                throw new ArgumentNullException(nameof(IAuthData.UserIdentity));
            }
            if (authData.KeyContent == null)
            {
                throw new ArgumentNullException(nameof(IAuthData.KeyContent));
            }

            IAuthenticationResponse response = null;

            IAuthData data = null;

            switch (authData.LoginType)
            {
            default:
            case enumLoginType.PassPhrase:
                data     = JsonConvert.DeserializeObject <AuthDataFromPassPhrase>(userData.ToString());
                response = await AuthWithLogin(data, key);

                break;
            }

            return(response);
        }
Ejemplo n.º 2
0
        public IAuthData GetDataInstance()
        {
            Type      typetoreturn = Type.GetType("Auth.DAL.MySqlDao.Auth_MySqlDao,Auth.DAL");
            IAuthData oRetorno     = (IAuthData)Activator.CreateInstance(typetoreturn);

            return(oRetorno);
        }
Ejemplo n.º 3
0
        private async Task <IAuthenticationResponse> AuthWithLogin(IAuthData authData, string key)
        {
            var data     = (AuthDataFromPassPhrase)authData;
            var response = new AuthenticationResponse();

            try
            {
                response.User = await authRepository.LogIn(data.UserIdentity.ToString(), data.SystemCode);

                if (response.User != null)
                {
                    var senha = CryptoUtils.Decrypt(response.User.DescSenha, key);
                    response.Logged = string.Equals(senha, authData.KeyContent.ToString());
                    if (response.Logged)
                    {
                        response.User.DescSenha = string.Empty;
                        authRepository.LogarTentativaAcesso(authData.UserIdentity.ToString(), authData.SystemCode, response.Logged, response.User.IdUsuario);
                    }
                    else
                    {
                        throw new Exception("Usuário/Senha inválido!");
                    }
                }
                else
                {
                    throw new Exception("Usuário não encontrado");
                }
            }
            catch (Exception ex)
            {
                response.Logged = false;
                authRepository.LogarTentativaAcesso(authData.UserIdentity.ToString(), authData.SystemCode, response.Logged, response.User?.IdUsuario, ex.Message);
                response.User   = null;
                response.Errors = response.Errors ?? new List <string>();
                response.Errors.Add(ex.Message);
            }

            return(response);
        }
 public AuthController(IAuthData authData, UserManager <ApplicationUser> userManager)
 {
     _authData    = authData;
     _userManager = userManager;
 }
Ejemplo n.º 5
0
 public AccessBusiness(IAccessData iAccessData, IAuthData authDataRepository)
 {
     _accessDataRepository = iAccessData;
     _authDataRepository   = authDataRepository;
 }
Ejemplo n.º 6
0
 public TokenBlacklistValidationMiddleware(RequestDelegate next, IAuthData authData)
 {
     _next     = next;
     _authData = authData;
 }