Beispiel #1
0
    def set_authentication(self,
                           provider=None,
                           oauth2_refresh_token=None,
                           username=None,
                           password=None,
                           proxy_config=None,
                           user_agent=None,
                           timeout=None):
        if provider == 'ptc':
            self._auth_provider = AuthPtc(user_agent=user_agent,
                                          timeout=timeout)
        elif provider == 'google':
            self._auth_provider = AuthGoogle()
        elif provider is None:
            self._auth_provider = None
        else:
            raise InvalidCredentialsException(
                "Invalid authentication provider - only ptc/google available.")

        self.log.debug('Auth provider: {}'.format(provider))

        if proxy_config:
            self._auth_provider.set_proxy(proxy_config)

        if oauth2_refresh_token is not None:
            self._auth_provider.set_refresh_token(oauth2_refresh_token)
        elif username and password:
            if not self._auth_provider.user_login(username, password):
                raise AuthException("User login failed!")
        else:
            raise InvalidCredentialsException(
                "Invalid Credential Input - Please provide username/password or an oauth2 refresh token"
            )
Beispiel #2
0
    def set_authentication(self,
                           provider=None,
                           oauth2_refresh_token=None,
                           username=None,
                           password=None):
        if provider == 'ptc':
            self._auth_provider = AuthPtc()
        elif provider == 'google':
            self._auth_provider = AuthGoogle()
        elif provider is None:
            self._auth_provider = None
        else:
            raise AuthException(
                "Invalid authentication provider - only ptc/google available.")

        self.log.debug('Auth provider: %s', provider)

        if oauth2_refresh_token is not None:
            self._auth_provider.set_refresh_token(oauth2_refresh_token)
        elif username is not None and password is not None:
            self._auth_provider.user_login(username, password)
        else:
            raise AuthException(
                "Invalid Credential Input - Please provide username/password or an oauth2 refresh token"
            )
Beispiel #3
0
    def initialize_api(self):
        device_info = get_device_info(self.account)
        self.logged_in = False
        self.ever_authenticated = False
        self.empty_visits = 0
        self.account_seen = 0

        self.api = PGoApi(device_info=device_info)
        if config.HASH_KEY:
            self.api.activate_hash_server(config.HASH_KEY)
        self.api.set_position(*self.location)
        if self.proxy:
            self.api.set_proxy({'http': self.proxy, 'https': self.proxy})
        self.api.set_logger(self.logger)
        if self.account.get('provider') == 'ptc' and self.account.get(
                'refresh'):
            self.api._auth_provider = AuthPtc(
                username=self.username,
                password=self.account['password'],
                timeout=config.LOGIN_TIMEOUT)
            self.api._auth_provider.set_refresh_token(
                self.account.get('refresh'))
            self.api._auth_provider._access_token = self.account.get('auth')
            self.api._auth_provider._access_token_expiry = self.account.get(
                'expiry')
            if self.api._auth_provider.check_access_token():
                self.api._auth_provider._login = True
                self.logged_in = True
                self.ever_authenticated = True
Beispiel #4
0
    def login(self, provider, username, password, lat = None, lng = None, alt = None, app_simulation = True):

        if (lat is not None) and (lng is not None) and (alt is not None):
            self._position_lat = lat
            self._position_lng = lng
            self._position_alt = alt

        if not isinstance(username, six.string_types) or not isinstance(password, six.string_types):
            raise AuthException("Username/password not correctly specified")

        if provider == 'ptc':
            self._auth_provider = AuthPtc()
        elif provider == 'google':
            self._auth_provider = AuthGoogle()
        else:
            raise AuthException("Invalid authentication provider - only ptc/google available.")

        self.log.debug('Auth provider: %s', provider)

        if not self._auth_provider.login(username, password):
            self.log.info('Login process failed')
            return False

        if app_simulation:
            self.log.info('Starting RPC login sequence (app simulation)')

            # making a standard call, like it is also done by the client
            request = self.create_request()

            request.get_player()
            request.get_hatched_eggs()
            request.get_inventory()
            request.check_awarded_badges()
            request.download_settings(hash="05daf51635c82611d1aac95c0b051d3ec088a930")

            response = request.call()
        else:
            self.log.info('Starting minimal RPC login sequence')
            response = self.get_player()

        if not response:
            self.log.info('Login failed!')
            return False

        if 'api_url' in response:
            self._api_endpoint = ('https://{}/rpc'.format(response['api_url']))
            self.log.debug('Setting API endpoint to: %s', self._api_endpoint)
        else:
            self.log.error('Login failed - unexpected server response!')
            return False

        if app_simulation:
            self.log.info('Finished RPC login sequence (app simulation)')
        else:
            self.log.info('Finished minimal RPC login sequence')

        self.log.info('Login process completed')

        return True
Beispiel #5
0
    def login(self, provider, username, password, cached=False):
        if not isinstance(username, basestring) or not isinstance(
                password, basestring):
            raise AuthException("Username/password not correctly specified")

        if provider == 'ptc':
            self._auth_provider = AuthPtc()
        elif provider == 'google':
            self._auth_provider = AuthGoogle()
        else:
            raise AuthException(
                "Invalid authentication provider - only ptc/google available.")

        self.log.debug('Auth provider: %s', provider)

        if not self._auth_provider.login(username, password):
            self.log.info('Login process failed')
            return False

        self.log.info('Starting RPC login sequence (app simulation)')
        self.get_player()
        self.get_hatched_eggs()
        self.get_inventory()
        self.check_awarded_badges()
        self.download_settings(hash="05daf51635c82611d1aac95c0b051d3ec088a930"
                               )  # not sure what this is but dont change it

        response = self.call()

        if not response:
            self.log.info('Login failed!')
        if os.path.isfile("auth_cache") and cached:
            response = pickle.load(open("auth_cache"))
        fname = "auth_cache_%s" % username
        if os.path.isfile(fname) and cached:
            response = pickle.load(open(fname))
        else:
            response = self.heartbeat()
            f = open(fname, "w")
            pickle.dump(response, f)
        if not response:
            self.log.info('Login failed!')
            return False

        if 'api_url' in response:
            self._api_endpoint = ('https://{}/rpc'.format(response['api_url']))
            self.log.debug('Setting API endpoint to: %s', self._api_endpoint)
        else:
            self.log.error('Login failed - unexpected server response!')
            return False

        if 'auth_ticket' in response:
            self._auth_provider.set_ticket(response['auth_ticket'].values())

        self.log.info('Finished RPC login sequence (app simulation)')
        self.log.info('Login process completed')

        return True
Beispiel #6
0
def main():
    try:
        if hasattr(config, 'AUTHKEY'):
            authkey = config.AUTHKEY
        else:
            authkey = b'm3wtw0'

        if hasattr(config, 'HASH_KEY'):
            HASH_KEY = config.HASH_KEY
        else:
            HASH_KEY = None

        class AccountManager(BaseManager):
            pass

        AccountManager.register('captcha_queue')
        AccountManager.register('extra_queue')
        manager = AccountManager(address=get_address(), authkey=authkey)
        manager.connect()
        captcha_queue = manager.captcha_queue()
        extra_queue = manager.extra_queue()

        middle_lat = (config.MAP_START[0] + config.MAP_END[0]) / 2
        middle_lon = (config.MAP_START[1] + config.MAP_END[1]) / 2
        middle_alt = random_altitude()

        driver = webdriver.Chrome()
        driver.set_window_size(803, 807)

        while not captcha_queue.empty():
            account = captcha_queue.get()
            username = account.get('username')
            location = account.get('location')
            if location and location != (0, 0, 0):
                lat, lon, alt = location
            else:
                lat = uniform(middle_lat - 0.001, middle_lat + 0.001)
                lon = uniform(middle_lon - 0.001, middle_lon + 0.001)
                alt = uniform(middle_alt - 10, middle_alt + 10)

            try:
                device_info = get_device_info(account)
                api = PGoApi(device_info=device_info)
                if HASH_KEY:
                    api.activate_hash_server(HASH_KEY)
                api.set_position(lat, lon, alt)

                authenticated = False
                if account.get('provider') == 'ptc' and account.get('refresh'):
                    api._auth_provider = AuthPtc()
                    api._auth_provider.set_refresh_token(
                        account.get('refresh'))
                    api._auth_provider._access_token = account.get('auth')
                    api._auth_provider._access_token_expiry = account.get(
                        'expiry')
                    if api._auth_provider.check_access_token():
                        print(username, 'already authenticated')
                        api._auth_provider._login = True
                        authenticated = True

                if not authenticated:
                    print(username)
                    api.set_authentication(username=username,
                                           password=account.get('password'),
                                           provider=account.get('provider'))

                request = api.create_request()
                request.download_remote_config_version(platform=1,
                                                       app_version=5301)
                request.check_challenge()
                request.get_hatched_eggs()
                request.get_inventory()
                request.check_awarded_badges()
                request.download_settings()
                response = request.call()
                account['time'] = time()

                responses = response.get('responses', {})
                challenge_url = responses.get('CHECK_CHALLENGE',
                                              {}).get('challenge_url', ' ')
                timestamp = responses.get('GET_INVENTORY',
                                          {}).get('inventory_delta',
                                                  {}).get('new_timestamp_ms')
                account['location'] = lat, lon, alt
                account['inventory_timestamp'] = timestamp
                if challenge_url == ' ':
                    account['captcha'] = False
                    extra_queue.put(account)
                else:
                    if resolve_captcha(challenge_url, api, driver, timestamp):
                        account['time'] = time()
                        account['captcha'] = False
                        extra_queue.put(account)
                    else:
                        account['time'] = time()
                        print('failure')
                        captcha_queue.put(account)
            except (KeyboardInterrupt, Exception) as e:
                print(e)
                captcha_queue.put(account)
                break
            except (exceptions.AuthException,
                    exceptions.AuthTokenExpiredException,
                    exceptions.AuthTokenExpiredException):
                print('Authentication error')
                captcha_queue.put(account)
                sleep(2)
    finally:
        try:
            driver.close()
        except Exception:
            pass
Beispiel #7
0
        lat, lon, alt = location
    else:
        lat = uniform(middle_lat - 0.001, middle_lat + 0.001)
        lon = uniform(middle_lon - 0.001, middle_lon + 0.001)
        alt = uniform(middle_alt - 10, middle_alt + 10)

    try:
        device_info = get_device_info(account)
        api = PGoApi(device_info=device_info)
        if HASH_KEY:
            api.activate_hash_server(HASH_KEY)
        api.set_position(lat, lon, alt)

        authenticated = False
        if account.get('provider') == 'ptc' and account.get('refresh'):
            api._auth_provider = AuthPtc()
            api._auth_provider.set_refresh_token(account.get('refresh'))
            api._auth_provider._access_token = account.get('auth')
            api._auth_provider._access_token_expiry = account.get('expiry')
            if api._auth_provider.check_access_token():
                print(username, 'already authenticated')
                api._auth_provider._login = True
                authenticated = True

        if not authenticated:
            print(username)
            api.set_authentication(username=username,
                                   password=account.get('password'),
                                   provider=account.get('provider'))

        request = api.create_request()