Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): OAuth2 scopes does not save #4820

Merged
merged 2 commits into from Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/cli/src/credentials/oauth2Credential.api.ts
Expand Up @@ -78,26 +78,32 @@ 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,
);

// 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,
);
Expand Down Expand Up @@ -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;
Expand Down