Arrow Flight Client Node.js
Sur cette page

Authentification du client Flight

Indiquez l’adresse de votre serveur Flight. Pour les connexions TLS, le client utilise par défaut les certificats racines approuvés par le système.

Jeton Bearer

Placez le jeton dans la variable d’environnement FLIGHT_TOKEN. Le client envoie les métadonnées authorization à chaque appel.

bearer.ts
import { FlightClient } from 'arrow-flight-client';

async function main() {
  const token = process.env.FLIGHT_TOKEN;

  if (!token) {
    throw new Error('Set FLIGHT_TOKEN before connecting');
  }

  const client = new FlightClient('flight.example.com:443', {
    tls: {},
    metadata: {
      authorization: `Bearer ${token}`
    }
  });

  try {
    for await (const flight of client.listFlights()) {
      console.log(flight);
    }
  }
  finally {
    await client.close();
  }
}

await main();

Authentification TLS mutuelle

Si le serveur exige mTLS, fournissez le certificat racine approuvé et les identifiants du client.

mutual-tls.ts
import { readFileSync } from 'node:fs';
import { FlightClient } from 'arrow-flight-client';

async function main() {
  const client = new FlightClient('flight.example.com:443', {
    tls: {
      rootCertificates: readFileSync('./certs/ca.pem'),
      privateKey: readFileSync('./certs/client.key'),
      certificateChain: readFileSync('./certs/client.pem')
    }
  });

  try {
    for await (const flight of client.listFlights()) {
      console.log(flight);
    }
  }
  finally {
    await client.close();
  }
}

await main();

Les chemins des certificats sont relatifs au répertoire de travail du processus. Fournissez privateKey et certificateChain ensemble.