@citrineos/util
Version:
The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.
24 lines • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractBasicCredentials = extractBasicCredentials;
const StringOperations_1 = require("./StringOperations");
/**
* Extracts credentials from the Authorization header.
*
* The Authorization header is formatted as follows:
* AUTHORIZATION: Basic <Base64 encoded(<Configured ChargingStationId>:<Configured BasicAuthPassword>)>
*
* @param {http.IncomingMessage} req - The request object.
* @returns Extracted credentials.
*/
function extractBasicCredentials(req) {
const authHeader = req.headers.authorization;
if (!(authHeader === null || authHeader === void 0 ? void 0 : authHeader.startsWith('Basic '))) {
return {};
}
const base64Credentials = authHeader.split(' ')[1];
const decodedCredentials = Buffer.from(base64Credentials, 'base64').toString();
const [username, password] = (0, StringOperations_1.splitOnce)(decodedCredentials, ':');
return { username, password };
}
//# sourceMappingURL=RequestOperations.js.map