From ea47e8b1bc85f561b11d65c9b4b07a462c8adc2d Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Wed, 13 May 2020 00:40:05 +0200 Subject: [PATCH] :zap: Fix issue that OAuth data got overwritten with every save #PROD-22 --- packages/cli/src/Server.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 8249712255..ab72359eb3 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -755,6 +755,21 @@ class App { throw new Error('No encryption key got found to encrypt the credentials!'); } + // Load the currently saved credentials to be able to persist some of the data if + const result = await Db.collections.Credentials!.findOne(id); + if (result === undefined) { + throw new ResponseHelper.ResponseError(`Credentials with the id "${id}" do not exist.`, undefined, 400); + } + + const currentlySavedCredentials = new Credentials(result.name, result.type, result.nodesAccess, result.data); + const decryptedData = currentlySavedCredentials.getData(encryptionKey!); + + // Do not overwrite the oauth data else data like the access or refresh token would get lost + // everytime anybody changes anything on the credentials even if it is just the name. + if (decryptedData.oauthTokenData) { + incomingData.data.oauthTokenData = decryptedData.oauthTokenData; + } + // Encrypt the data const credentials = new Credentials(incomingData.name, incomingData.type, incomingData.nodesAccess); credentials.setData(incomingData.data, encryptionKey);