UNPKG

@citrineos/util

Version:

The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.

25 lines 981 B
// SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project // // SPDX-License-Identifier: Apache-2.0 import { IncomingMessage } from 'http'; import { splitOnce } from './StringOperations.js'; /** * 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. */ export function extractBasicCredentials(req) { const authHeader = req.headers.authorization; if (!authHeader?.startsWith('Basic ')) { return {}; } const base64Credentials = authHeader.split(' ')[1]; const decodedCredentials = Buffer.from(base64Credentials, 'base64').toString(); const [username, password] = splitOnce(decodedCredentials, ':'); return { username, password }; } //# sourceMappingURL=RequestOperations.js.map