mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(HTTP Request Node): New http request generic custom auth credential (#5798)
This commit is contained in:
parent
1abd172f73
commit
b17b4582a0
|
@ -0,0 +1,28 @@
|
||||||
|
/* eslint-disable n8n-nodes-base/cred-class-field-name-unsuffixed */
|
||||||
|
/* eslint-disable n8n-nodes-base/cred-class-name-unsuffixed */
|
||||||
|
import type { ICredentialType, INodeProperties } from 'n8n-workflow';
|
||||||
|
|
||||||
|
export class HttpCustomAuth implements ICredentialType {
|
||||||
|
name = 'httpCustomAuth';
|
||||||
|
|
||||||
|
displayName = 'Custom Auth';
|
||||||
|
|
||||||
|
documentationUrl = 'httpRequest';
|
||||||
|
|
||||||
|
genericAuth = true;
|
||||||
|
|
||||||
|
icon = 'node:n8n-nodes-base.httpRequest';
|
||||||
|
|
||||||
|
properties: INodeProperties[] = [
|
||||||
|
{
|
||||||
|
displayName: 'JSON',
|
||||||
|
name: 'json',
|
||||||
|
type: 'json',
|
||||||
|
required: true,
|
||||||
|
description: 'Use json to specify authentication values for headers, body and qs.',
|
||||||
|
placeholder:
|
||||||
|
'{ "headers": { "key" : "value" }, "body": { "key": "value" }, "qs": { "key": "value" } }',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
|
@ -6,8 +6,9 @@ import type {
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
JsonObject,
|
JsonObject,
|
||||||
|
IRequestOptionsSimplified,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
import { NodeApiError, NodeOperationError, jsonParse } from 'n8n-workflow';
|
||||||
|
|
||||||
import type { OptionsWithUri } from 'request';
|
import type { OptionsWithUri } from 'request';
|
||||||
import type { RequestPromiseOptions } from 'request-promise-native';
|
import type { RequestPromiseOptions } from 'request-promise-native';
|
||||||
|
@ -36,6 +37,15 @@ export class GraphQL implements INodeType {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'httpCustomAuth',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: ['customAuth'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'httpDigestAuth',
|
name: 'httpDigestAuth',
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -92,6 +102,10 @@ export class GraphQL implements INodeType {
|
||||||
name: 'Basic Auth',
|
name: 'Basic Auth',
|
||||||
value: 'basicAuth',
|
value: 'basicAuth',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Custom Auth',
|
||||||
|
value: 'customAuth',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Digest Auth',
|
name: 'Digest Auth',
|
||||||
value: 'digestAuth',
|
value: 'digestAuth',
|
||||||
|
@ -284,6 +298,7 @@ export class GraphQL implements INodeType {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
let httpBasicAuth;
|
let httpBasicAuth;
|
||||||
let httpDigestAuth;
|
let httpDigestAuth;
|
||||||
|
let httpCustomAuth;
|
||||||
let httpHeaderAuth;
|
let httpHeaderAuth;
|
||||||
let httpQueryAuth;
|
let httpQueryAuth;
|
||||||
let oAuth1Api;
|
let oAuth1Api;
|
||||||
|
@ -294,6 +309,11 @@ export class GraphQL implements INodeType {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
httpCustomAuth = await this.getCredentials('httpCustomAuth');
|
||||||
|
} catch (error) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
httpDigestAuth = await this.getCredentials('httpDigestAuth');
|
httpDigestAuth = await this.getCredentials('httpDigestAuth');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -361,6 +381,21 @@ export class GraphQL implements INodeType {
|
||||||
pass: httpBasicAuth.password as string,
|
pass: httpBasicAuth.password as string,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
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 };
|
||||||
|
}
|
||||||
|
if (customAuth.body) {
|
||||||
|
requestOptions.body = { ...requestOptions.body, ...customAuth.body };
|
||||||
|
}
|
||||||
|
if (customAuth.qs) {
|
||||||
|
requestOptions.qs = { ...requestOptions.qs, ...customAuth.qs };
|
||||||
|
}
|
||||||
|
}
|
||||||
if (httpHeaderAuth !== undefined) {
|
if (httpHeaderAuth !== undefined) {
|
||||||
requestOptions.headers![httpHeaderAuth.name as string] = httpHeaderAuth.value;
|
requestOptions.headers![httpHeaderAuth.name as string] = httpHeaderAuth.value;
|
||||||
}
|
}
|
||||||
|
@ -387,6 +422,7 @@ export class GraphQL implements INodeType {
|
||||||
} else {
|
} else {
|
||||||
if (requestFormat === 'json') {
|
if (requestFormat === 'json') {
|
||||||
requestOptions.body = {
|
requestOptions.body = {
|
||||||
|
...requestOptions.body,
|
||||||
query: gqlQuery,
|
query: gqlQuery,
|
||||||
variables: this.getNodeParameter('variables', itemIndex, {}) as object,
|
variables: this.getNodeParameter('variables', itemIndex, {}) as object,
|
||||||
operationName: this.getNodeParameter('operationName', itemIndex) as string,
|
operationName: this.getNodeParameter('operationName', itemIndex) as string,
|
||||||
|
|
|
@ -8,6 +8,7 @@ import type {
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeBaseDescription,
|
INodeTypeBaseDescription,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
|
IRequestOptionsSimplified,
|
||||||
JsonObject,
|
JsonObject,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
@ -969,6 +970,7 @@ export class HttpRequestV3 implements INodeType {
|
||||||
let httpDigestAuth;
|
let httpDigestAuth;
|
||||||
let httpHeaderAuth;
|
let httpHeaderAuth;
|
||||||
let httpQueryAuth;
|
let httpQueryAuth;
|
||||||
|
let httpCustomAuth;
|
||||||
let oAuth1Api;
|
let oAuth1Api;
|
||||||
let oAuth2Api;
|
let oAuth2Api;
|
||||||
let nodeCredentialType;
|
let nodeCredentialType;
|
||||||
|
@ -992,6 +994,10 @@ export class HttpRequestV3 implements INodeType {
|
||||||
try {
|
try {
|
||||||
httpQueryAuth = await this.getCredentials('httpQueryAuth');
|
httpQueryAuth = await this.getCredentials('httpQueryAuth');
|
||||||
} catch {}
|
} catch {}
|
||||||
|
} else if (genericAuthType === 'httpCustomAuth') {
|
||||||
|
try {
|
||||||
|
httpCustomAuth = await this.getCredentials('httpCustomAuth');
|
||||||
|
} catch {}
|
||||||
} else if (genericAuthType === 'oAuth1Api') {
|
} else if (genericAuthType === 'oAuth1Api') {
|
||||||
try {
|
try {
|
||||||
oAuth1Api = await this.getCredentials('oAuth1Api');
|
oAuth1Api = await this.getCredentials('oAuth1Api');
|
||||||
|
@ -1345,6 +1351,24 @@ export class HttpRequestV3 implements INodeType {
|
||||||
};
|
};
|
||||||
authDataKeys.auth = ['pass'];
|
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 (requestOptions.headers!.accept === undefined) {
|
||||||
if (responseFormat === 'json') {
|
if (responseFormat === 'json') {
|
||||||
|
|
|
@ -152,6 +152,7 @@
|
||||||
"dist/credentials/HttpBasicAuth.credentials.js",
|
"dist/credentials/HttpBasicAuth.credentials.js",
|
||||||
"dist/credentials/HttpDigestAuth.credentials.js",
|
"dist/credentials/HttpDigestAuth.credentials.js",
|
||||||
"dist/credentials/HttpHeaderAuth.credentials.js",
|
"dist/credentials/HttpHeaderAuth.credentials.js",
|
||||||
|
"dist/credentials/HttpCustomAuth.credentials.js",
|
||||||
"dist/credentials/HttpQueryAuth.credentials.js",
|
"dist/credentials/HttpQueryAuth.credentials.js",
|
||||||
"dist/credentials/HubspotApi.credentials.js",
|
"dist/credentials/HubspotApi.credentials.js",
|
||||||
"dist/credentials/HubspotAppToken.credentials.js",
|
"dist/credentials/HubspotAppToken.credentials.js",
|
||||||
|
|
Loading…
Reference in a new issue