fix(core): OAuth2 scopes does not save

This commit is contained in:
Michael Kret 2022-12-05 18:28:34 +02:00 committed by GitHub
parent 67aad63343
commit 7aefed46dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -78,12 +78,14 @@ oauth2CredentialController.get(
throw new ResponseHelper.InternalServerError((error as Error).message);
}
const credentialType = (credential as unknown as ICredentialsEncrypted).type;
const mode: WorkflowExecuteMode = 'internal';
const timezone = config.getEnv('generic.timezone');
const credentialsHelper = new CredentialsHelper(encryptionKey);
const decryptedDataOriginal = await credentialsHelper.getDecrypted(
credential as INodeCredentialsDetails,
(credential as unknown as ICredentialsEncrypted).type,
credentialType,
mode,
timezone,
true,
@ -91,13 +93,17 @@ oauth2CredentialController.get(
// 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) {
if (
decryptedDataOriginal?.scope &&
credentialType.includes('OAuth2') &&
!['oAuth2Api'].includes(credentialType)
) {
delete decryptedDataOriginal.scope;
}
const oauthCredentials = credentialsHelper.applyDefaultsAndOverwrites(
decryptedDataOriginal,
(credential as unknown as ICredentialsEncrypted).type,
credentialType,
mode,
timezone,
);
@ -128,7 +134,7 @@ oauth2CredentialController.get(
// Encrypt the data
const credentials = new Credentials(
credential as INodeCredentialsDetails,
(credential as unknown as ICredentialsEncrypted).type,
credentialType,
(credential as unknown as ICredentialsEncrypted).nodesAccess,
);
decryptedDataOriginal.csrfSecret = csrfSecret;