Voyz / ibeam

IBeam is an authentication and maintenance tool used for the Interactive Brokers Client Portal Web API Gateway.
Apache License 2.0
581 stars 115 forks source link

Google 2FA bug in __str__ method #194

Closed perrycyl closed 4 months ago

perrycyl commented 5 months ago

Describe the bug When the str method is invoked on google_msg_handler it is unable to reference driver_path since it does not exist.

To Reproduce Steps to reproduce the behavior:

  1. docker run --env-file env.list -p 5000:5000 voyz/ibeam:0.5.4-rc2
  2. Watch logs

Expected behavior The Google message QR code pairing statement and link should be displayed at some point.

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

Additional context Env.list:

IBEAM_ACCOUNT=Account1234
IBEAM_PASSWORD=Password1234
IBEAM_TWO_FA_HANDLER=GOOGLE_MSG
IBEAM_TWO_FA_SELECT_TARGET=One Time Passcode
IBEAM_PAGE_LOAD_TIMEOUT=60
IBEAM_OAUTH_TIMEOUT=30
IBEAM_TWO_FA_EL_ID=ID@@xyz-field-silver-response
IBEAM_TWO_FA_INPUT_EL_ID=ID@@xyz-field-silver-response

Error message:

2024-06-19 12:28:14 ibeam  | 2024-06-19 16:28:14,558|I| Authentication strategy: "B"
2024-06-19 12:28:14 ibeam  | 2024-06-19 16:28:14,558|I| No active sessions, logging in...
2024-06-19 12:28:14 ibeam  | 2024-06-19 16:28:14,558|I| Loading auth webpage at https://localhost:5000/sso/Login?forwardTo=22&RL=1&ip2loc=on
2024-06-19 12:28:21 ibeam  | 2024-06-19 16:28:21,839|I| Gateway auth webpage loaded
2024-06-19 12:28:21 ibeam  | 2024-06-19 16:28:21,839|I| Login attempt number 1
2024-06-19 12:28:27 ibeam  | 2024-06-19 16:28:27,294|I| Submitting the form
2024-06-19 12:28:28 ibeam  | 2024-06-19 16:28:28,108|I| Credentials correct, but Gateway requires two-factor authentication.
2024-06-19 12:28:28 ibeam  | 2024-06-19 16:28:28,109|I| Cleaning up the resources. Display: <pyvirtualdisplay.display.Display object at 0xffffab4288d0> | Driver: <selenium.webdriver.chrome.webdriver.WebDriver (session="4e6bfefc45fba33bd48cf3ec09de240b")>
2024-06-19 12:28:28 ibeam  | 2024-06-19 16:28:28,109|E| Error encountered during authentication 
2024-06-19 12:28:28 ibeam  | Exception:
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/ibeam_starter.py", line 172, in <module>
2024-06-19 12:28:28 ibeam  |     success, shutdown, status = client.start_and_authenticate()
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/gateway_client.py", line 62, in start_and_authenticate
2024-06-19 12:28:28 ibeam  |     success, shutdown, status = self.strategy_handler.try_authenticating(request_retries=request_retries)
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/handlers/strategy_handler.py", line 85, in try_authenticating
2024-06-19 12:28:28 ibeam  |     return self._authentication_strategy_B(status, request_retries)
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/handlers/strategy_handler.py", line 140, in _authentication_strategy_B
2024-06-19 12:28:28 ibeam  |     return self._log_in(status)
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/handlers/strategy_handler.py", line 151, in _log_in
2024-06-19 12:28:28 ibeam  |     success, shutdown = self.login_handler.login()
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/handlers/login_handler.py", line 447, in login
2024-06-19 12:28:28 ibeam  |     self.attempt(targets, wait_and_identify_trigger, driver)
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/handlers/login_handler.py", line 380, in attempt
2024-06-19 12:28:28 ibeam  |     trigger, target = self.step_two_fa(targets, wait_and_identify_trigger, driver, self.two_fa_handler, self.strict_two_fa_code)
2024-06-19 12:28:28 ibeam  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/handlers/login_handler.py", line 258, in step_two_fa
2024-06-19 12:28:28 ibeam  |     two_fa_code = handle_two_fa(two_fa_handler, driver, strict_two_fa_code)
2024-06-19 12:28:28 ibeam  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/handlers/login_handler.py", line 78, in handle_two_fa
2024-06-19 12:28:28 ibeam  |     _LOGGER.info(f'Attempting to acquire 2FA code from: {two_fa_handler}')
2024-06-19 12:28:28 ibeam  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/two_fa_handlers/google_msg_handler.py", line 123, in __str__
2024-06-19 12:28:28 ibeam  |     return f"GoogleMessagesTwoFaHandler(driver_path={self.driver_path})"
2024-06-19 12:28:28 ibeam  |                                                      ^^^^^^^^^^^^^^^^
2024-06-19 12:28:28 ibeam  | 
2024-06-19 12:28:28 ibeam  |   <class 'AttributeError'> 'GoogleMessagesTwoFaHandler' object has no attribute 'driver_path'
2024-06-19 12:28:28 ibeam  | 2024-06-19 16:28:28,146|I| Logging in failed
2024-06-19 12:28:28 ibeam  | 2024-06-19 16:28:28,150|I| Starting maintenance with interval 60 seconds

Suggest a Fix

2024-06-19 12:28:28 ibeam  |   File "/srv/ibeam/src/two_fa_handlers/google_msg_handler.py", line 123, in __str__
2024-06-19 12:28:28 ibeam  |     return f"GoogleMessagesTwoFaHandler(driver_path={self.driver_path})"

Identifies the issue, which seems to be that self.driver_path is not readily available but doesn't seem to be needed.

Voyz commented 5 months ago

Hey @perrycyl many thanks for trying out IBeam and reporting this 👍 The Google Messages handler has been contributed by another user, hence I don't get a chance to keep taps on it until someone else reports some issues as my setup uses a different type of 2FA.

I've just pushed voyz/ibeam:0.5.4-rc3 fixing both of your issues with the Google Messages handler - let me know if it works.

perrycyl commented 5 months ago

RC3 fixes the issues. Awesome.

Voyz commented 4 months ago

I'm going to close this Issue as it is now fixed in voyz/ibeam:0.5.4. Let me know if you'd like to reopen it and continue the discussion. Thanks for contributing 👍