Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand All @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down