From a11177ef1f0a3c563a90bb4eede473ba71d19fc2 Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Thu, 3 Dec 2020 00:51:36 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Update=20authentication=20scheme=20?= =?UTF-8?q?(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jupyter_forward/core.py | 20 +++++++++++++++++--- setup.cfg | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/jupyter_forward/core.py b/jupyter_forward/core.py index 41f987f..298445e 100644 --- a/jupyter_forward/core.py +++ b/jupyter_forward/core.py @@ -5,6 +5,7 @@ from dataclasses import dataclass import invoke +import paramiko from fabric import Connection @@ -45,11 +46,14 @@ def __post_init__(self): connect_kwargs = {} if self.identity: connect_kwargs['key_filename'] = [self.identity] - else: - connect_kwargs['password'] = getpass.getpass() self.session = Connection(self.host, connect_kwargs=connect_kwargs, forward_agent=True) - self.session.open() + try: + self.session.open() + except paramiko.ssh_exception.BadAuthenticationType: + loc_transport = self.session.client.get_transport() + loc_transport.auth_interactive_dumb(self.session.user, _authentication_handler) + self.session.transport = loc_transport def dir_exists(self, directory): """ @@ -228,3 +232,13 @@ def parse_stdout(stdout: str): token = result.query.split('token=')[-1].strip() break return {'hostname': hostname, 'port': port, 'token': token, 'url': url} + + +def _authentication_handler(title, instructions, prompt_list): + """ + Handler for paramiko auth_interactive_dumb + """ + resp = [] + for pr in prompt_list: + resp.append(getpass.getpass(str(pr[0]))) + return resp diff --git a/setup.cfg b/setup.cfg index dfe95f8..470bf65 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,7 +8,7 @@ extend-ignore = E203,E501,E402,W605 [isort] known_first_party=jupyter_forward -known_third_party=fabric,invoke,pkg_resources,pytest,setuptools,typer +known_third_party=fabric,invoke,paramiko,pkg_resources,pytest,setuptools,typer multi_line_output=3 include_trailing_comma=True force_grid_wrap=0