Beispiel #1
0
def test_refresh_token(credentials_prompt, refresh_token_cache):
    mock_google()
    refresh_token_cache.set('foo')
    cookies = auth.get_auth(credentials_prompt, refresh_token_cache)
    assert not credentials_prompt.was_prompted
    assert refresh_token_cache.get() is not None
    assert cookies['session'] == 'foo'
Beispiel #2
0
def get_auth_config(cookie_file, auth_file):
    """Wrapper for get_auth that reads from a config file"""

    config = configparser.ConfigParser()
    auth_file = auth_file

    def get_credentials_f():
        try:
            config.read(auth_file)
            email = config.get('icbot', 'email')
            password = config.get('icbot', 'password')

        except Exception as e:
            print("Config parser failed with error: '{}'".format(e))
            print("Switching to manual input.".format(e))
            email = input('Email: ')
            password = getpass.getpass()

        return (email, password)

    def get_pin_f():
        try:
            config.read(auth_file)
            pin = config.get('icbot', 'pin')
        except Exception as e:
            print("Config parser failed with error: '{}'".format(e))
            print("Switching to manual input.".format(e))
            pin = input('PIN: ')
        return pin

    return auth.get_auth(get_credentials_f, get_pin_f, cookie_file)
def test_refresh_token(credentials_prompt, refresh_token_cache):
    mock_google()
    refresh_token_cache.set('foo')
    cookies = auth.get_auth(credentials_prompt, refresh_token_cache)
    assert not credentials_prompt.was_prompted
    assert refresh_token_cache.get() is not None
    assert cookies['session'] == 'foo'
Beispiel #4
0
def get_auth_config(cookie_file, auth_file):
    """Wrapper for get_auth that reads from a config file"""

    config = configparser.ConfigParser()
    auth_file = auth_file

    def get_credentials_f():
        try:
            config.read(auth_file)
            email = config.get('icbot', 'email')
            password = config.get('icbot', 'password')

        except Exception as e:
            print("Config parser failed with error: '{}'".format(e))
            print("Switching to manual input.".format(e))
            email = input('Email: ')
            password = getpass.getpass()

        return (email, password)

    def get_pin_f():
        try:
            config.read(auth_file)
            pin = config.get('icbot', 'pin')
        except Exception as e:
            print("Config parser failed with error: '{}'".format(e))
            print("Switching to manual input.".format(e))
            pin = input('PIN: ')
        return pin

    return auth.get_auth(get_credentials_f, get_pin_f, cookie_file)
Beispiel #5
0
def test_manual_login(credentials_prompt, refresh_token_cache):
    mock_google()
    cookies = auth.get_auth(credentials_prompt,
                            refresh_token_cache,
                            manual_login=True)
    assert credentials_prompt.was_prompted
    assert refresh_token_cache.get() is not None
    assert cookies['session'] == 'foo'
Beispiel #6
0
def run_example(example_coroutine, *extra_args):
    """Run a hangups example coroutine.

    Args:
        example_coroutine (coroutine): Coroutine to run with a connected
            hangups client and arguments namespace as arguments.
        extra_args (str): Any extra command line arguments required by the
            example.
    """
    args = _get_parser().parse_args()
    logging.basicConfig(level=logging.DEBUG if args.debug else logging.WARNING)

    if args.login_and_save_token:
        cookies = hangups.auth.get_auth_stdin(args.token_path)
        #pprint(getmembers(args))
        return
    else:
        # Obtain hangups authentication cookies, prompting for credentials from
        # standard input if necessary.
        refresh_token_cache = RefreshTokenCache(args.token_path)
        try:
            cookies = get_auth(NullCredentialsPrompt(), refresh_token_cache)
        except:
            print(
                "Hangouts login failed. Either you didn't log in yet, or your refresh token expired.\nPlease log in with --login-and-save-token"
            )
            return

    while 1:
        print("Attempting main loop...")
        client = hangups.Client(cookies,
                                max_retries=float('inf'),
                                retry_backoff_base=1.2)
        task = asyncio.ensure_future(
            _async_main(example_coroutine, client, args))
        loop = asyncio.get_event_loop()

        try:
            loop.run_until_complete(task)
        except KeyboardInterrupt:
            task.cancel()
            loop.run_forever()
        except:
            pass
        finally:
            time.sleep(5)

    try:
        loop.run_until_complete(task)
    except KeyboardInterrupt:
        task.cancel()
        loop.run_forever()
    finally:
        loop.close()
Beispiel #7
0
 def client(self):
     """The hangups client object."""
     # Make sure the directory with cached credentials exists.
     ensure_directory_exists(os.path.dirname(self.cookie_file))
     return Client(
         get_auth(
             GoogleAccountCredentials(
                 email_address=self.config["email-address"],
                 config=self.config,
             ),
             RefreshTokenCache(self.cookie_file),
             manual_login=True,
         )
     )
    def client(self):
        """The hangups client object."""
        # Make sure the directory with cached credentials exists.
        ensure_directory_exists(os.path.dirname(self.cookie_file))

        dirs = appdirs.AppDirs('hangups', 'hangups')
        token_path = os.path.join(dirs.user_cache_dir, 'refresh_token.txt')

        return Client(
            get_auth(
                GoogleAccountCredentials(
                    email_address=self.config["email-address"],
                    password=get_secret(
                        options=self.config,
                        value_option="password",
                        name_option="password-name",
                        description="Google account password",
                    ),
                ),
                RefreshTokenCache(token_path),
            ))
Beispiel #9
0
def test_login_phone_verification(credentials_prompt, refresh_token_cache):
    mock_google(verification_input_id=auth.PHONE_CODE_SELECTOR[1:])
    cookies = auth.get_auth(credentials_prompt, refresh_token_cache)
    assert credentials_prompt.was_prompted
    assert refresh_token_cache.get() is not None
    assert cookies['session'] == 'foo'
def test_login_phone_verification(credentials_prompt, refresh_token_cache):
    mock_google(verification_input_id=auth.PHONE_CODE_SELECTOR[1:])
    cookies = auth.get_auth(credentials_prompt, refresh_token_cache)
    assert credentials_prompt.was_prompted
    assert refresh_token_cache.get() is not None
    assert cookies['session'] == 'foo'