mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(HTTP Request Node): New http request generic custom auth credential (#5798)
This commit is contained in:
@@ -6,8 +6,9 @@ import type {
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
JsonObject,
|
||||
IRequestOptionsSimplified,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeApiError, NodeOperationError, jsonParse } from 'n8n-workflow';
|
||||
|
||||
import type { OptionsWithUri } from 'request';
|
||||
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',
|
||||
required: true,
|
||||
@@ -92,6 +102,10 @@ export class GraphQL implements INodeType {
|
||||
name: 'Basic Auth',
|
||||
value: 'basicAuth',
|
||||
},
|
||||
{
|
||||
name: 'Custom Auth',
|
||||
value: 'customAuth',
|
||||
},
|
||||
{
|
||||
name: 'Digest Auth',
|
||||
value: 'digestAuth',
|
||||
@@ -284,6 +298,7 @@ export class GraphQL implements INodeType {
|
||||
const items = this.getInputData();
|
||||
let httpBasicAuth;
|
||||
let httpDigestAuth;
|
||||
let httpCustomAuth;
|
||||
let httpHeaderAuth;
|
||||
let httpQueryAuth;
|
||||
let oAuth1Api;
|
||||
@@ -294,6 +309,11 @@ export class GraphQL implements INodeType {
|
||||
} catch (error) {
|
||||
// Do nothing
|
||||
}
|
||||
try {
|
||||
httpCustomAuth = await this.getCredentials('httpCustomAuth');
|
||||
} catch (error) {
|
||||
// Do nothing
|
||||
}
|
||||
try {
|
||||
httpDigestAuth = await this.getCredentials('httpDigestAuth');
|
||||
} catch (error) {
|
||||
@@ -361,6 +381,21 @@ export class GraphQL implements INodeType {
|
||||
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) {
|
||||
requestOptions.headers![httpHeaderAuth.name as string] = httpHeaderAuth.value;
|
||||
}
|
||||
@@ -387,6 +422,7 @@ export class GraphQL implements INodeType {
|
||||
} else {
|
||||
if (requestFormat === 'json') {
|
||||
requestOptions.body = {
|
||||
...requestOptions.body,
|
||||
query: gqlQuery,
|
||||
variables: this.getNodeParameter('variables', itemIndex, {}) as object,
|
||||
operationName: this.getNodeParameter('operationName', itemIndex) as string,
|
||||
|
||||
Reference in New Issue
Block a user