React Native
React Native
Start SSH Tunnel Keyboard-Interactive Authentication
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.StartKeyboardAuth method, which begins keyboard-interactive authentication. The only argument is the login name. It returns XML describing the server's prompts, which are answered with ContinueKeyboardAuth.
Background: Keyboard-interactive is the prompt-driven authentication method: the server sends one or more questions — a password, a one-time code, a security question — and the client answers each. This is how a tunnel supports two-factor and other challenge-response schemes. The returned XML says exactly what to ask and whether to mask the input.
Chilkat React Native Downloads
import { SshTunnel } from '@chilkat/react-native'
async function chilkatExample() {
// Demonstrates the SshTunnel.StartKeyboardAuth method, which begins keyboard-interactive
// authentication. The only argument is the login name. It returns XML describing the server's
// prompts, which are answered with ContinueKeyboardAuth.
const tunnel = new SshTunnel();
// The tunnel forwards accepted local connections to this destination through the SSH server.
tunnel.destHostname = 'db.internal.example.com';
tunnel.destPort = 5432;
// Connect to the SSH server. This performs the TCP/proxy connection and SSH handshake, but
// does not authenticate yet.
const sshPort = 22;
try {
await tunnel.connectAsync('ssh.example.com', sshPort);
} catch {
console.log(tunnel.lastErrorText);
return;
}
// Begin keyboard-interactive authentication. The returned XML describes the server's prompts.
let infoRequestXml: string;
try {
infoRequestXml = await tunnel.startKeyboardAuthAsync('mySshLogin');
} catch {
console.log(tunnel.lastErrorText);
return;
}
console.log(infoRequestXml);
// Answer the prompt(s) with ContinueKeyboardAuth, then call BeginAccepting.
const waitForThreadExit = true;
try {
tunnel.closeTunnel(waitForThreadExit);
} catch {
console.log(tunnel.lastErrorText);
return;
}
}