From 22ca768c13406a86899e36a36dcc18d63f492723 Mon Sep 17 00:00:00 2001 From: David Ma <47725056+DMA902@users.noreply.github.com> Date: Tue, 5 Aug 2025 06:26:04 -0400 Subject: [PATCH] feat(core): Add Support for Additional Body Properties in OAuth2 API Client Credentials Flow (#16573) Co-authored-by: Elias Meire --- .../utils/request-helper-functions.ts | 25 +++++++++++------ .../credentials/OAuth2Api.credentials.ts | 28 +++++++++++++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts b/packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts index c52efef5e6..20bad1b1c5 100644 --- a/packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts @@ -929,6 +929,22 @@ export function applyPaginationRequestData( return merge({}, requestData, preparedPaginationData); } +function createOAuth2Client(credentials: OAuth2CredentialData): ClientOAuth2 { + return new ClientOAuth2({ + clientId: credentials.clientId, + clientSecret: credentials.clientSecret, + accessTokenUri: credentials.accessTokenUrl, + scopes: (credentials.scope as string).split(' '), + ignoreSSLIssues: credentials.ignoreSSLIssues, + authentication: credentials.authentication ?? 'header', + ...(credentials.additionalBodyProperties && { + additionalBodyProperties: jsonParse(credentials.additionalBodyProperties, { + fallbackValue: {}, + }), + }), + }); +} + /** @deprecated make these requests using httpRequestWithAuthentication */ export async function requestOAuth2( this: IAllExecuteFunctions, @@ -950,14 +966,7 @@ export async function requestOAuth2( throw new ApplicationError('OAuth credentials not connected'); } - const oAuthClient = new ClientOAuth2({ - clientId: credentials.clientId, - clientSecret: credentials.clientSecret, - accessTokenUri: credentials.accessTokenUrl, - scopes: (credentials.scope as string).split(' '), - ignoreSSLIssues: credentials.ignoreSSLIssues, - authentication: credentials.authentication ?? 'header', - }); + const oAuthClient = createOAuth2Client(credentials); let oauthTokenData = credentials.oauthTokenData as ClientOAuth2TokenData; // if it's the first time using the credentials, get the access token and save it into the DB. diff --git a/packages/nodes-base/credentials/OAuth2Api.credentials.ts b/packages/nodes-base/credentials/OAuth2Api.credentials.ts index a6789f6820..92b6f3d251 100644 --- a/packages/nodes-base/credentials/OAuth2Api.credentials.ts +++ b/packages/nodes-base/credentials/OAuth2Api.credentials.ts @@ -107,6 +107,34 @@ export class OAuth2Api implements ICredentialType { ], default: 'header', }, + { + displayName: 'Send Additional Body Properties', + name: 'sendAdditionalBodyProperties', + type: 'boolean', + default: false, + displayOptions: { + show: { + grantType: ['clientCredentials'], + authentication: ['body'], + }, + }, + }, + { + displayName: 'Additional Body Properties', + name: 'additionalBodyProperties', + type: 'json', + typeOptions: { + rows: 5, + }, + displayOptions: { + show: { + grantType: ['clientCredentials'], + authentication: ['body'], + sendAdditionalBodyProperties: [true], + }, + }, + default: '', + }, { displayName: 'Ignore SSL Issues (Insecure)', name: 'ignoreSSLIssues',