@@ -8510,33 +8510,9 @@ def get_chromium_driver_version(self):
85108510
85118511 def get_mfa_code(self, totp_key=None):
85128512 """Same as get_totp_code() and get_google_auth_password().
8513- Returns a time-based one-time password based on the
8514- Google Authenticator algorithm for multi-factor authentication.
8515- If the "totp_key" is not specified, this method defaults
8516- to using the one provided in [seleniumbase/config/settings.py].
8517- Google Authenticator codes expire & change at 30-sec intervals.
8518- If the fetched password expires in the next 1.2 seconds, waits
8519- for a new one before returning it (may take up to 1.2 seconds).
8520- See https://pyotp.readthedocs.io/en/latest/ for details."""
8521- import pyotp
8522-
8523- if not totp_key:
8524- totp_key = settings.TOTP_KEY
8525-
8526- epoch_interval = time.time() / 30.0
8527- cycle_lifespan = float(epoch_interval) - int(epoch_interval)
8528- if float(cycle_lifespan) > 0.96:
8529- # Password expires in the next 1.2 seconds. Wait for a new one.
8530- for i in range(30):
8531- time.sleep(0.04)
8532- epoch_interval = time.time() / 30.0
8533- cycle_lifespan = float(epoch_interval) - int(epoch_interval)
8534- if not float(cycle_lifespan) > 0.96:
8535- # The new password cycle has begun
8536- break
8537-
8538- totp = pyotp.TOTP(totp_key)
8539- return str(totp.now())
8513+ Returns a time-based one-time password based on the Google
8514+ Authenticator algorithm for multi-factor authentication."""
8515+ return shared_utils.get_mfa_code(totp_key)
85408516
85418517 def enter_mfa_code(
85428518 self, selector, totp_key=None, by="css selector", timeout=None
0 commit comments