UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

30 lines 1.25 kB
import { __awaiter } from "tslib"; export const BasicAuthentication = function (credentials, self) { if (!(this instanceof BasicAuthentication)) { return new BasicAuthentication(credentials, self); } else { self.credentials = { username: credentials.username, password: credentials.password, type: credentials.type }; const BasicAuthentication = function () { }; BasicAuthentication.prototype.getAuthenticationHeaders = () => __awaiter(this, void 0, void 0, function* () { const headers = {}; let credential = `${credentials.username}:${credentials.password}`; // accessing an undefined variable Buffer in the browser throws a reference error if (typeof Buffer !== "undefined") { credential = Buffer.from(credential, "binary").toString("base64"); } else { credential = btoa(credential); } headers["Authorization"] = `Basic ${credential}`; return headers; }); return new BasicAuthentication(credentials, self); } }; export default BasicAuthentication; //# sourceMappingURL=BasicAuthentication.js.map