From 7cb5dc2aa5d15c574b0e07d0d7fa23dd9a9996ea Mon Sep 17 00:00:00 2001
From: Michael Kret <88898367+michael-radency@users.noreply.github.com>
Date: Thu, 1 Dec 2022 15:08:02 +0200
Subject: [PATCH] fix(core): OAuth2 scope saved to DB fix

---
 packages/cli/src/credentials/oauth2Credential.api.ts | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/packages/cli/src/credentials/oauth2Credential.api.ts b/packages/cli/src/credentials/oauth2Credential.api.ts
index e3fe834d43..e3fb2c0d2e 100644
--- a/packages/cli/src/credentials/oauth2Credential.api.ts
+++ b/packages/cli/src/credentials/oauth2Credential.api.ts
@@ -89,6 +89,12 @@ oauth2CredentialController.get(
 			true,
 		);
 
+		// At some point in the past we saved hidden scopes to credentials (but shouldn't)
+		// Delete scope before applying defaults to make sure new scopes are present on reconnect
+		if (decryptedDataOriginal?.scope) {
+			delete decryptedDataOriginal.scope;
+		}
+
 		const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(
 			decryptedDataOriginal,
 			(credential as unknown as ICredentialsEncrypted).type,