public AuthInfoDTO GetSecretDateAndPin(string nuid) { WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK; try { IList <authentication_info> authInfo = GetAuthInfoByNuid(nuid); if (authInfo == null || authInfo.Count() == 0) { return(null); } else { AuthInfoDTO result = new AuthInfoDTO(); result.NUID = authInfo.First().NUID; result.PIN = authInfo.First().PIN; if (result.PIN.Equals("DISABLED")) { result.ANSWER = ClsTripleDES.Decrypt(authInfo.First().ANSWER); } else { result.ANSWER = authInfo.First().ANSWER; } return(result); } } catch (Exception ex) { throw ex; } }
public async Task <Response <AuthInfoDTO> > Authenticate(CredentialsDTO dto) { var user = await _usersRepository.GetByEmail(dto.Email); var isPasswordValid = false; try { isPasswordValid = await ValidatePassword(dto.Password, user); } catch (Exception e) { _logger.LogError(e, e.Message); return(new SecurityErrorResponse <AuthInfoDTO>(new [] { new Error { Code = ErrorCodes.Security.AuthDataInvalid, Message = ErrorMessages.Security.AuthDataInvalid } })); } if (user == null || !isPasswordValid) { return(new SecurityErrorResponse <AuthInfoDTO>(new [] { new Error { Code = ErrorCodes.Security.AuthDataInvalid, Message = ErrorMessages.Security.AuthDataInvalid } })); } var tokenDTO = await _tokenFactory.CreateToken(user); var userDTO = _mapper.Map <UserModel, UserDTO>(user); var result = new AuthInfoDTO { User = userDTO, Token = tokenDTO }; return(new Response <AuthInfoDTO> { Data = result }); }
public async Task <Response <AuthInfoDTO> > Authenticate(AuthDTO dto) { var userEntity = await _userRepository.GetUserByEmail(dto.Email); if (userEntity == null || userEntity.Password != dto.Password) { return(new SecurityErrorResponse <AuthInfoDTO>(new Error[0])); } var tokenDto = await _tokensFactory.CreateToken(userEntity); var userDto = _mapper.Map <UserModel, UserDTO>(userEntity); var authInfo = new AuthInfoDTO { User = userDto, Token = tokenDto, }; return(new Response <AuthInfoDTO> { ResultData = authInfo, }); }
public async Task <Response <AuthInfoDTO> > GoogleAuthenticate(string googleToken) { GoogleJsonWebSignature.Payload infoFromGoogleToken; try { infoFromGoogleToken = await GoogleJsonWebSignature.ValidateAsync(googleToken); } catch { return(new ForbiddenErrorResponse <AuthInfoDTO>(new[] { new Error { Code = ErrorCodes.Security.GoogleTokenInvalid, Message = ErrorMessages.Security.GoogleTokenInvalid, Field = ErrorFields.User.GoogleToken } })); } //TODO: think how validate google token /* * if ((string) infoFromGoogleToken.Audience != _googleSettings.Value.ClientId) * { * return new PermissionDeniedErrorResponse<AuthInfoDTO>(new[] * { * new Error * { * Code = ErrorCodes.Security.GoogleTokenInvalid, * Message = ErrorMessages.Security.GoogleTokenInvalid, * Field = ErrorFields.User.GoogleToken * } * }); * } */ var user = await _usersRepository.GetByEmail(infoFromGoogleToken.Email); if (user == null) { return(new BusinessConflictErrorResponse <AuthInfoDTO>(new [] { new Error { Code = ErrorCodes.Business.UserDoesNotExists, Message = ErrorMessages.Business.UserDoesNotExists, Field = ErrorFields.User.GoogleToken } })); } var tokenDTO = await _tokenFactory.CreateToken(user); var userDTO = _mapper.Map <UserModel, UserDTO>(user); var result = new AuthInfoDTO { User = userDTO, Token = tokenDTO }; return(new Response <AuthInfoDTO> { Data = result }); }