UNPKG

@platformatic/kafka

Version:

Modern and performant client for Apache Kafka

22 lines (21 loc) 840 B
import { createPromisifiedCallback, kCallbackPromise } from "../../apis/callbacks.js"; import { getCredential } from "./utils.js"; export function authenticate(authenticateAPI, connection, usernameProvider, passwordProvider, callback) { if (!callback) { callback = createPromisifiedCallback(); } getCredential('SASL/PLAIN username', usernameProvider, (error, username) => { if (error) { callback(error, undefined); return; } getCredential('SASL/PLAIN password', passwordProvider, (error, password) => { if (error) { callback(error, undefined); return; } authenticateAPI(connection, Buffer.from(['', username, password].join('\0')), callback); }); }); return callback[kCallbackPromise]; }