Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: asks user for OTP in CLI #636

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 63 additions & 3 deletions stores/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import math
import os
import platform
import stdiomask
import time
from contextlib import contextmanager
from datetime import datetime
Expand Down Expand Up @@ -420,10 +421,69 @@ def login(self):
if captcha_entry:
self.handle_captcha(False)
if self.driver.title in amazon_config["TWOFA_TITLES"]:
log.info("enter in your two-step verification code in browser")
while self.driver.title in amazon_config["TWOFA_TITLES"]:
# Wait for the user to enter 2FA
otp_select = None
timeout = self.get_timeout()
while True:
try:
otp_select = self.driver.find_element_by_xpath(
'//*[@id="auth-select-device-form"]'
)
break
except sel_exceptions.NoSuchElementException:
pass
if time.time() > timeout:
break
if otp_select:
log.info("OTP choice selection, trying to check TOTP (app) option")
try:
self.driver.find_element_by_xpath(
'//*[contains(@class, "auth-TOTP")]/label'
).click()
except sel_exceptions.NoSuchElementException:
log.error("OTP TOTP choice not present!")
self.driver.find_element_by_xpath('//*[@id="auth-send-code"]').click()
time.sleep(2)

self.notification_handler.play_notify_sound()
self.send_notification(
"Bot requires OTP input, please see console and/or browser window!",
"otp-page",
self.take_screenshots,
)
otp_field = None
timeout = self.get_timeout()
while True:
try:
otp_field = self.driver.find_element_by_xpath(
'//*[@id="auth-mfa-otpcode"]'
)
break
except sel_exceptions.NoSuchElementException:
pass
if time.time() > timeout:
break
if otp_field:
log.info("OTP Remember me checkbox")
try:
self.driver.find_element_by_xpath(
'//*[@name="rememberDevice"]'
).click()
except sel_exceptions.NoSuchElementException:
log.error("OTP Remember me checkbox did not exist")
otp = stdiomask.getpass(
prompt="enter in your two-step verification code: ", mask="*"
)
otp_field.send_keys(otp + Keys.RETURN)
time.sleep(2)
if self.driver.title in amazon_config["TWOFA_TITLES"]:
log.error("Something went wrong, please check browser manually...")
while self.driver.title in amazon_config["TWOFA_TITLES"]:
time.sleep(2)
else:
log.error("OTP entry box did not exist, please fill in OTP manually...")
while self.driver.title in amazon_config["TWOFA_TITLES"]:
# Wait for the user to enter 2FA
time.sleep(2)
log.info(f'Logged in as {amazon_config["username"]}')

@debug
Expand Down