fixed car connector token setting storage
MODIFY
src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts
src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts
@@ -26,14 +26,14 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat
public async connect(): Promise<string> {
if (!this.checkIfTokenExpired(this.connection.token)) {
- return this.connection.token.accessToken;
+ return await Cypher.decrypt(this.tenant, this.connection.token.accessToken);
}
// Check if connection is initialized
this.checkConnectionIsProvided();
// Get credential params
const credentials = await this.getCredentialURLParams();
- const response = await this.fetchNewToken(credentials);
- return response.accessToken;
+ const token = await this.fetchNewToken(credentials);
+ return Cypher.decrypt(this.tenant, token.accessToken);
}
public async getCurrentSoC(car: Car): Promise<number> {
@@ -95,16 +95,17 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat
}),
`Time out error (5s) when getting the token with the connection URL '${this.connection.tronityConnection.apiUrl}/oauth/authentication'`
);
- const data = response.data;
const currentTime = new Date();
const token : CarConnectorConnectionToken = {
- accessToken: data.access_token,
- tokenType: data.token_type,
- expiresIn: data.expires_in,
+ accessToken: await Cypher.encrypt(this.tenant, response.data.access_token),
+ tokenType: response.data.token_type,
+ expiresIn: response.data.expires_in,
issued: currentTime,
- expires: new Date(currentTime.getTime() + data.expires_in * 1000)
+ expires: new Date(currentTime.getTime() + response.data.expires_in * 1000)
};
this.connection.token = token;
+ // Sensitive data will be handled by helper method in the future
+ this.settings.sensitiveData.push(`content.carConnector.connections[${this.settings.carConnector.connections.indexOf(this.connection)}].token.accessToken`);
await SettingStorage.saveCarConnectorSettings(this.tenant, this.settings);
return token;
}

MODIFY
src/storage/mongodb/SettingStorage.ts
src/storage/mongodb/SettingStorage.ts
@@ -214,16 +214,20 @@ export default class SettingStorage {
return carConnectorSettings;
}
- public static async saveCarConnectorSettings(tenant: Tenant, carConnectorSettings: CarConnectorSettings): Promise<string> {
- const { id, identifier, backupSensitiveData, sensitiveData } = carConnectorSettings;
- const setting: SettingDB = {
- id, identifier, sensitiveData, backupSensitiveData,
+ public static async saveCarConnectorSettings(tenant: Tenant, carConnectorSettingToSave: CarConnectorSettings): Promise<void> {
+ // Build internal structure
+ const settingsToSave = {
+ id: carConnectorSettingToSave.id,
+ identifier: carConnectorSettingToSave.identifier,
+ lastChangedOn: new Date(),
+ sensitiveData: carConnectorSettingToSave.sensitiveData,
content: {
- type: carConnectorSettings.type,
- carConnector: carConnectorSettings.carConnector,
+ type: carConnectorSettingToSave.type,
+ carConnector: carConnectorSettingToSave.carConnector
},
- };
- return SettingStorage.saveSettings(tenant, setting);
+ } as SettingDB;
+ // Save
+ await SettingStorage.saveSettings(tenant, settingsToSave);
}
public static async getPricingSettings(tenant: Tenant, limit?: number, skip?: number, dateFrom?: Date, dateTo?: Date): Promise<PricingSettings> {

fixed car connector token setting storage