UNPKG

@talentsoft-opensource/widget-display-tool

Version:

Widget Simulator

36 lines (35 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sha1 = require("sha1"); function padleft(nbr) { return nbr.toString().padStart(2, "0"); } function formatDate(date) { const yyyy = date.getUTCFullYear(); const MM = padleft(date.getUTCMonth() + 1); //January is 0! const dd = padleft(date.getUTCDate()); const HH = padleft(date.getUTCHours()); const mm = padleft(date.getUTCMinutes()); return `${yyyy}${MM}${dd}${HH}${mm}`; } function getDirectConnectHash(secretKey, login, date) { const tokenBase = secretKey + formatDate(date) + login; return sha1(tokenBase).toUpperCase(); } class DirectConnectSecurityMode { getSecurityHeaderParams(secretKey, login, date) { const directConnectHash = getDirectConnectHash(secretKey, login, date); return { "x-login": login, "x-api-token": directConnectHash }; } getSecurityQueryParams(secretKey, login, date) { const directConnectHash = getDirectConnectHash(secretKey, login, date); return { "x-login": login, "x-api-token": directConnectHash }; } } exports.DirectConnectSecurityMode = DirectConnectSecurityMode;