mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(core): Add Support for Additional Body Properties in OAuth2 API Client Credentials Flow (#16573)
Co-authored-by: Elias Meire <elias@meire.dev>
This commit is contained in:
@@ -929,6 +929,22 @@ export function applyPaginationRequestData(
|
|||||||
return merge({}, requestData, preparedPaginationData);
|
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 */
|
/** @deprecated make these requests using httpRequestWithAuthentication */
|
||||||
export async function requestOAuth2(
|
export async function requestOAuth2(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
@@ -950,14 +966,7 @@ export async function requestOAuth2(
|
|||||||
throw new ApplicationError('OAuth credentials not connected');
|
throw new ApplicationError('OAuth credentials not connected');
|
||||||
}
|
}
|
||||||
|
|
||||||
const oAuthClient = new ClientOAuth2({
|
const oAuthClient = createOAuth2Client(credentials);
|
||||||
clientId: credentials.clientId,
|
|
||||||
clientSecret: credentials.clientSecret,
|
|
||||||
accessTokenUri: credentials.accessTokenUrl,
|
|
||||||
scopes: (credentials.scope as string).split(' '),
|
|
||||||
ignoreSSLIssues: credentials.ignoreSSLIssues,
|
|
||||||
authentication: credentials.authentication ?? 'header',
|
|
||||||
});
|
|
||||||
|
|
||||||
let oauthTokenData = credentials.oauthTokenData as ClientOAuth2TokenData;
|
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.
|
// if it's the first time using the credentials, get the access token and save it into the DB.
|
||||||
|
|||||||
@@ -107,6 +107,34 @@ export class OAuth2Api implements ICredentialType {
|
|||||||
],
|
],
|
||||||
default: 'header',
|
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)',
|
displayName: 'Ignore SSL Issues (Insecure)',
|
||||||
name: 'ignoreSSLIssues',
|
name: 'ignoreSSLIssues',
|
||||||
|
|||||||
Reference in New Issue
Block a user