Added more information on OCPI wrong Token
MODIFY
src/server/ocpi/OCPIServer.ts
src/server/ocpi/OCPIServer.ts
@@ -16,6 +16,7 @@ import { StatusCodes } from 'http-status-codes';
import { TenantComponents } from '../../types/Tenant';
import TenantStorage from '../../storage/mongodb/TenantStorage';
import Utils from '../../utils/Utils';
+import UtilsService from '../rest/v1/service/UtilsService';
const MODULE_NAME = 'OCPIServer';
@@ -58,6 +59,7 @@ export default class OCPIServer {
private async initialize(req: Request, res: Response, next: NextFunction): Promise<void> {
try {
+ const urlInfo = UtilsService.getURLInfo(req);
// Get Token
if (!req.headers || !req.headers.authorization) {
throw new AppError({
@@ -65,7 +67,8 @@ export default class OCPIServer {
action: ServerAction.OCPI_ENDPOINT,
errorCode: StatusCodes.UNAUTHORIZED,
message: 'Missing authorization token',
- ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
+ ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR,
+ detailedMessages: urlInfo,
});
}
let decodedToken: { tenant: string; tid: string };
@@ -79,7 +82,7 @@ export default class OCPIServer {
errorCode: StatusCodes.UNAUTHORIZED,
message: 'Invalid authorization token',
ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR,
- detailedMessages: { error: error.stack }
+ detailedMessages: { ...urlInfo, error: error.stack }
});
}
const tenantSubdomain = decodedToken.tenant ?? decodedToken.tid;
@@ -91,7 +94,8 @@ export default class OCPIServer {
action: ServerAction.OCPI_ENDPOINT,
errorCode: StatusCodes.UNAUTHORIZED,
message: `The Tenant '${tenantSubdomain}' does not exist`,
- ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR
+ ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR,
+ detailedMessages: { ...urlInfo, token }
});
}
req.tenant = tenant;
@@ -101,7 +105,8 @@ export default class OCPIServer {
action: ServerAction.OCPI_ENDPOINT,
errorCode: StatusCodes.UNAUTHORIZED,
message: `The Tenant '${tenantSubdomain}' does not support OCPI`,
- ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR
+ ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR,
+ detailedMessages: { ...urlInfo, token }
});
}
// Get Endpoint
@@ -111,8 +116,9 @@ export default class OCPIServer {
module: MODULE_NAME, method: 'initialize',
action: ServerAction.OCPI_ENDPOINT,
errorCode: StatusCodes.UNAUTHORIZED,
- message: 'Invalid Token',
- ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR
+ message: 'The OCPI Token does no longer exist in the OCPI endpoints',
+ ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR,
+ detailedMessages: { ...urlInfo, token }
});
}
req.ocpiEndpoint = ocpiEndpoint;
@@ -122,8 +128,9 @@ export default class OCPIServer {
module: MODULE_NAME, method: 'initialize',
action: ServerAction.OCPI_ENDPOINT,
errorCode: StatusCodes.UNAUTHORIZED,
- message: `Invalid Token for URL '${req.url}', endpoint role is '${ocpiEndpoint.role}'`,
- ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR
+ message: `Invalid OCPI Token for URL '${req.url}', OCPI Endpoint role is '${ocpiEndpoint.role}'`,
+ ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR,
+ detailedMessages: { ...urlInfo, token }
});
}
next();

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -2,6 +2,7 @@ import { Action, AuthorizationFilter, Entity } from '../../../../types/Authoriza
import { BillingAccount, BillingInvoice } from '../../../../types/Billing';
import { Car, CarCatalog } from '../../../../types/Car';
import ChargingStation, { ChargePoint } from '../../../../types/ChargingStation';
+import { EntityData, URLInfo } from '../../../../types/GlobalType';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
import Tenant, { TenantComponents } from '../../../../types/Tenant';
@@ -25,7 +26,6 @@ import CompanyStorage from '../../../../storage/mongodb/CompanyStorage';
import Constants from '../../../../utils/Constants';
import Cypher from '../../../../utils/Cypher';
import { DataResult } from '../../../../types/DataResult';
-import { EntityData } from '../../../../types/GlobalType';
import { Log } from '../../../../types/Log';
import LogStorage from '../../../../storage/mongodb/LogStorage';
import Logging from '../../../../utils/Logging';
@@ -54,6 +54,15 @@ import moment from 'moment';
const MODULE_NAME = 'UtilsService';
export default class UtilsService {
+ public static getURLInfo(req: Request): URLInfo {
+ return {
+ httpFullUrl: req.originalUrl,
+ httpUrl: req.url,
+ httpMethod: req.method,
+ group: Utils.getPerformanceRecordGroupFromURL(req.originalUrl),
+ };
+ }
+
public static async assignCreatedUserToSites(tenant: Tenant, user: User, authorizationFilter?: AuthorizationFilter) {
// Assign user to sites
if (Utils.isTenantComponentActive(tenant, TenantComponents.ORGANIZATION)) {

MODIFY
src/types/GlobalType.ts
src/types/GlobalType.ts
@@ -6,6 +6,7 @@ import Company from './Company';
import JsonOCPPServer from '../server/ocpp/json/JsonOCPPServer';
import { Log } from './Log';
import MongoDBStorage from '../storage/mongodb/MongoDBStorage';
+import { PerformanceRecordGroup } from './Performance';
import PricingDefinition from './Pricing';
import RegistrationToken from './RegistrationToken';
import { ServerType } from './Server';
@@ -26,6 +27,13 @@ export interface Data {
id: string;
}
+export interface URLInfo {
+ httpUrl: string;
+ httpFullUrl: string;
+ httpMethod: string;
+ group: PerformanceRecordGroup;
+}
+
export interface DatabaseCount {
count?: number;
}

Added more information on OCPI wrong Token