ibeam icon indicating copy to clipboard operation
ibeam copied to clipboard

Old clientportal.gw can't login with Mobile Authenticator App Code

Open b3kan opened this issue 1 year ago • 1 comments

Describe the bug I wasn't able to login to live account that has Mobile Authenticator App code, even when I tried to login with URL.

To Reproduce Steps to reproduce the behavior:

  1. Add Mobile Authenticator App Code to your account
  2. Try to add custom two FA handler that will return 6 digit code depended on your secret key.
  3. Run ibeam and it will fail, even if you try to input correct credentials and correct code in browser.

Expected behavior Ibeam must be able to detect new input field to input 2FA code and login successfully.

Environment IBeam version: 0.5.4 Docker image or standalone: 0.5.4 Python version (standalone users only): OS: MacOS

Suggest a Fix

  1. Upgrade latest clientportal.gw
  2. ibeam/src/vars.py

TWO_FA_MAAC_ID = os.environ.get("IBEAM_TWO_FA_MAAC_ID", "ID@@xyz-field-silver-response") # Mobile Authenticator App Code 3. ibeam/src/login/targets.py after line 92, in create_target method add

targets['TWO_FA_MAAC'] = Target(cnf.TWO_FA_MAAC_ID) # Mobile Authenticator App Code

  1. ibeam/src/handlers/login_handler.py after line 198, in step_login method add

is_visible(targets['TWO_FA_MAAC']),

so line 192-199 must look like

trigger, target = wait_and_identify_trigger( has_text(targets['SUCCESS']), is_visible(targets['TWO_FA']), is_visible(targets['TWO_FA_SELECT']), is_visible(targets['TWO_FA_NOTIFICATION']), is_visible(targets['ERROR']), is_clickable(targets['IBKEY_PROMO']), is_visible(targets['TWO_FA_MAAC']), )

  1. ibeam/src/handlers/login_handler.py after line 388, in attempt method add

if target == targets["TWO_FA_MAAC"]: trigger, target = self.step_two_fa_maac(targets, wait_and_identify_trigger, driver, self.two_fa_handler, self.strict_two_fa_code)

  1. In same class please add this method anywhere
 def step_two_fa_maac(self, targets, wait_and_identify_trigger, driver, two_fa_handler, strict_two_fa_code):
        _LOGGER.info(f'Credentials correct, but Gateway requires two-factor authentication.')
        if two_fa_handler is None:
            _LOGGER.critical(
                    f'######## ATTENTION! ######## No 2FA handler found. You may define your own 2FA handler or use built-in handlers. See documentation for more: https://github.com/Voyz/ibeam/wiki/Two-Factor-Authentication')
            raise AttemptException(cause='shutdown')

        two_fa_code = handle_two_fa(two_fa_handler, driver, strict_two_fa_code)

        if two_fa_code is None:
            _LOGGER.warning(f'No 2FA code returned. Aborting authentication.')
            raise AttemptException(cause='break')
        else:
            two_fa_el, _ = wait_and_identify_trigger(is_clickable(targets['TWO_FA_MAAC']), skip_identify=True)

            two_fa_el.clear()
            two_fa_el.send_keys(two_fa_code)

            _LOGGER.info('Submitting the 2FA form')
            two_fa_el.send_keys(Keys.RETURN)

            trigger, target = wait_and_identify_trigger(
                    has_text(targets['SUCCESS']),
                    is_clickable(targets['IBKEY_PROMO']),
                    is_visible(targets['ERROR'])
            )

            return trigger, target

You know better so you can refactor my suggestion.

b3kan avatar Jul 26 '24 10:07 b3kan

Hey @b3kan thanks for reporting your issue.

It would be great to see the output log of IBeam when encountering this error if you could share it.

Your suggested solution makes me guess that it would be an issue similar to the one described in #185, a solution for which was setting the following env vars:

IBEAM_TWO_FA_EL_ID=ID@@xyz-field-silver-response
IBEAM_TWO_FA_INPUT_EL_ID=ID@@xyz-field-silver-response

Can you check if that works for you?

In #185 there was no need to update the clientportal.gw. It's more that IBKR sends different versions of the website to different users (still no idea why), which is why a lot of the HTML query targets are customisable through env vars as in the solution I shared above.

Voyz avatar Aug 06 '24 10:08 Voyz

I'm going to close this issue due to inactivity. Thanks for your contribution and please feel free to request a reopen if you'd like to continue the discussion 👍

Voyz avatar Oct 30 '24 12:10 Voyz