@platformatic/kafka
Version:
Modern and performant client for Apache Kafka
20 lines (19 loc) • 824 B
JavaScript
import { createPromisifiedCallback, kCallbackPromise } from "../../apis/callbacks.js";
import { getCredential } from "./credential-provider.js";
export function authenticate(authenticateAPI, connection, usernameProvider, passwordProvider, callback) {
if (!callback) {
callback = createPromisifiedCallback();
}
getCredential('SASL/PLAIN username', usernameProvider, (error, username) => {
if (error) {
return callback(error, undefined);
}
getCredential('SASL/PLAIN password', passwordProvider, (error, password) => {
if (error) {
return callback(error, undefined);
}
authenticateAPI(connection, Buffer.from(['', username, password].join('\0')), callback);
});
});
return callback[kCallbackPromise];
}