diff --git a/index.js b/index.js index 17eea64..c7f7955 100644 --- a/index.js +++ b/index.js @@ -35,11 +35,15 @@ async function createServer(options) { }); } -async function createSSHConnection(config) { +async function createSSHConnection(config, keyboardInteractiveHandler) { return new Promise(function (resolve, reject) { let conn = new Client(); conn.on('ready', () => resolve(conn)); conn.on('error', reject); + // It should be set before connect(). + if (keyboardInteractiveHandler){ + conn.on('keyboard-interactive', keyboardInteractiveHandler); + } conn.connect(config); }); } @@ -58,7 +62,7 @@ async function createTunnel( tunnelOptions, serverOptions, sshOptions, forwardOp return new Promise(async function (resolve, reject) { try { - sshConnection = await createSSHConnection(sshOptionslocal); + sshConnection = await createSSHConnection(sshOptionslocal, tunnelOptionsLocal.keyboardInteractiveHandler); addListenerSshConnection(sshConnection); } catch (e) { if (server) { diff --git a/types/index.d.ts b/types/index.d.ts index 8e9ed8d..031f6d5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -36,6 +36,18 @@ export interface TunnelOptions { * @default false */ reconnectOnError: boolean; + /* + * specifies handler for keyboard-interactive authentication + * @default undefined + * @see https://www.npmjs.com/package/ssh2?activeTab=readme#client-events + */ + keyboardInteractiveHandler?: ( + name: string, + instructions: string, + instructionsLang: string, + prompts: { prompt: string; echo: boolean }[], + finish: (responses: string[]) => void + ) => void; } /**