Skip to content

Commit

Permalink
Custom UI sample
Browse files Browse the repository at this point in the history
  • Loading branch information
sk-keeper authored and aaunario-keeper committed Jun 21, 2024
1 parent d074922 commit a553df0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
42 changes: 42 additions & 0 deletions examples/custom_login_ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import logging

from keepercommander.auth import login_steps
from keepercommander import api
from keepercommander.__main__ import get_params_from_config


class CustomUi(login_steps.LoginUi):
def on_device_approval(self, step):
try:
step.send_push(login_steps.DeviceApprovalChannel.Email)
except Exception as e:
logging.error(e)
verification_code = wait_for_verification_code()
step.send_code(login_steps.DeviceApprovalChannel.Email, verification_code)

def on_two_factor(self, step):
raise NotImplementedError()

def on_password(self, step):
password = wait_for_password()
try:
step.verify_password(password)
except Exception as e:
logging.error(e)

def on_sso_redirect(self, step):
raise NotImplementedError()

def on_sso_data_key(self, step):
raise NotImplementedError()


my_params = get_params_from_config('config.json')
while not my_params.user:
my_params.user = input('User(Email): ')

ui = CustomUi()
api.login(my_params, login_ui=ui)

if not my_params.session_token:
exit(1)
6 changes: 3 additions & 3 deletions keepercommander/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def run_command(params, request):
return rest_api.v2_execute(params.rest_context, request)


def login(params, new_login=False):
# type: (KeeperParams, bool) -> None
def login(params, new_login=False, login_ui=None):
# type: (KeeperParams, bool, Optional[Any]) -> None

logging.info('Logging in to Keeper Commander')
flow = loginv3.LoginV3Flow()
flow = loginv3.LoginV3Flow(login_ui)
try:
flow.login(params, new_login=new_login)
except loginv3.InvalidDeviceToken:
Expand Down

0 comments on commit a553df0

Please sign in to comment.