feat(HTTP Request Node): New http request generic custom auth credential (#5798)

This commit is contained in:
Marcus
2023-06-29 15:27:02 +02:00
committed by GitHub
parent 1abd172f73
commit b17b4582a0
4 changed files with 90 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ import type {
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
IRequestOptionsSimplified,
JsonObject,
} from 'n8n-workflow';
@@ -969,6 +970,7 @@ export class HttpRequestV3 implements INodeType {
let httpDigestAuth;
let httpHeaderAuth;
let httpQueryAuth;
let httpCustomAuth;
let oAuth1Api;
let oAuth2Api;
let nodeCredentialType;
@@ -992,6 +994,10 @@ export class HttpRequestV3 implements INodeType {
try {
httpQueryAuth = await this.getCredentials('httpQueryAuth');
} catch {}
} else if (genericAuthType === 'httpCustomAuth') {
try {
httpCustomAuth = await this.getCredentials('httpCustomAuth');
} catch {}
} else if (genericAuthType === 'oAuth1Api') {
try {
oAuth1Api = await this.getCredentials('oAuth1Api');
@@ -1345,6 +1351,24 @@ export class HttpRequestV3 implements INodeType {
};
authDataKeys.auth = ['pass'];
}
if (httpCustomAuth !== undefined) {
const customAuth = jsonParse<IRequestOptionsSimplified>(
(httpCustomAuth.json as string) || '{}',
{ errorMessage: 'Invalid Custom Auth JSON' },
);
if (customAuth.headers) {
requestOptions.headers = { ...requestOptions.headers, ...customAuth.headers };
authDataKeys.headers = Object.keys(customAuth.headers);
}
if (customAuth.body) {
requestOptions.body = { ...requestOptions.body, ...customAuth.body };
authDataKeys.body = Object.keys(customAuth.body);
}
if (customAuth.qs) {
requestOptions.qs = { ...requestOptions.qs, ...customAuth.qs };
authDataKeys.qs = Object.keys(customAuth.qs);
}
}
if (requestOptions.headers!.accept === undefined) {
if (responseFormat === 'json') {