@citrineos/util
Version:
The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.
44 lines • 2.4 kB
JavaScript
;
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Authenticator = void 0;
const tslog_1 = require("tslog");
class Authenticator {
constructor(unknownStationFilter, connectedStationFilter, networkProfileFilter, basicAuthenticationFilter, logger) {
this._unknownStationFilter = unknownStationFilter;
this._connectedStationFilter = connectedStationFilter;
this._networkProfileFilter = networkProfileFilter;
this._basicAuthenticationFilter = basicAuthenticationFilter;
this._logger = logger
? logger.getSubLogger({ name: this.constructor.name })
: new tslog_1.Logger({ name: this.constructor.name });
}
authenticate(request, options) {
return __awaiter(this, void 0, void 0, function* () {
const identifier = this._getClientIdFromUrl(request.url);
this._logger.debug(`Starting authentication for identifier: ${identifier}`);
yield this._unknownStationFilter.authenticate(identifier, request, options);
yield this._connectedStationFilter.authenticate(identifier, request, options);
yield this._networkProfileFilter.authenticate(identifier, request, options);
yield this._basicAuthenticationFilter.authenticate(identifier, request, options);
this._logger.debug(`Authentication successful for identifier: ${identifier}`);
return { identifier };
});
}
_getClientIdFromUrl(url) {
return url.split('/').pop();
}
}
exports.Authenticator = Authenticator;
//# sourceMappingURL=Authenticator.js.map