mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
✨ Add OAuth, basicAuth, digestAuth and queryAuth support to GraphQL node (#2673)
* ✨ Add OAuth support to GraphQL node * ✨ Add basicAuth, digestAuth and queryAuth to GraphQL node
This commit is contained in:
parent
7ff7c53fc1
commit
3d4c1cb23f
|
@ -25,6 +25,28 @@ export class GraphQL implements INodeType {
|
||||||
inputs: ['main'],
|
inputs: ['main'],
|
||||||
outputs: ['main'],
|
outputs: ['main'],
|
||||||
credentials: [
|
credentials: [
|
||||||
|
{
|
||||||
|
name: 'httpBasicAuth',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'basicAuth',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'httpDigestAuth',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'digestAuth',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'httpHeaderAuth',
|
name: 'httpHeaderAuth',
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -36,6 +58,39 @@ export class GraphQL implements INodeType {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'httpQueryAuth',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'queryAuth',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'oAuth1Api',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'oAuth1',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'oAuth2Api',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'oAuth2',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
|
@ -43,10 +98,30 @@ export class GraphQL implements INodeType {
|
||||||
name: 'authentication',
|
name: 'authentication',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Basic Auth',
|
||||||
|
value: 'basicAuth',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Digest Auth',
|
||||||
|
value: 'digestAuth',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Header Auth',
|
name: 'Header Auth',
|
||||||
value: 'headerAuth',
|
value: 'headerAuth',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Query Auth',
|
||||||
|
value: 'queryAuth',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'OAuth1',
|
||||||
|
value: 'oAuth1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'OAuth2',
|
||||||
|
value: 'oAuth2',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'None',
|
name: 'None',
|
||||||
value: 'none',
|
value: 'none',
|
||||||
|
@ -229,7 +304,12 @@ export class GraphQL implements INodeType {
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
|
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
|
const httpBasicAuth = await this.getCredentials('httpBasicAuth');
|
||||||
|
const httpDigestAuth = await this.getCredentials('httpDigestAuth');
|
||||||
const httpHeaderAuth = await this.getCredentials('httpHeaderAuth');
|
const httpHeaderAuth = await this.getCredentials('httpHeaderAuth');
|
||||||
|
const httpQueryAuth = await this.getCredentials('httpQueryAuth');
|
||||||
|
const oAuth1Api = await this.getCredentials('oAuth1Api');
|
||||||
|
const oAuth2Api = await this.getCredentials('oAuth2Api');
|
||||||
|
|
||||||
let requestOptions: OptionsWithUri & RequestPromiseOptions;
|
let requestOptions: OptionsWithUri & RequestPromiseOptions;
|
||||||
|
|
||||||
|
@ -260,15 +340,35 @@ export class GraphQL implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add credentials if any are set
|
// Add credentials if any are set
|
||||||
|
if (httpBasicAuth !== undefined) {
|
||||||
|
requestOptions.auth = {
|
||||||
|
user: httpBasicAuth.user as string,
|
||||||
|
pass: httpBasicAuth.password as string,
|
||||||
|
};
|
||||||
|
}
|
||||||
if (httpHeaderAuth !== undefined) {
|
if (httpHeaderAuth !== undefined) {
|
||||||
requestOptions.headers![httpHeaderAuth.name as string] = httpHeaderAuth.value;
|
requestOptions.headers![httpHeaderAuth.name as string] = httpHeaderAuth.value;
|
||||||
}
|
}
|
||||||
|
if (httpQueryAuth !== undefined) {
|
||||||
|
if (!requestOptions.qs) {
|
||||||
|
requestOptions.qs = {};
|
||||||
|
}
|
||||||
|
requestOptions.qs![httpQueryAuth.name as string] = httpQueryAuth.value;
|
||||||
|
}
|
||||||
|
if (httpDigestAuth !== undefined) {
|
||||||
|
requestOptions.auth = {
|
||||||
|
user: httpDigestAuth.user as string,
|
||||||
|
pass: httpDigestAuth.password as string,
|
||||||
|
sendImmediately: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const gqlQuery = this.getNodeParameter('query', itemIndex, '') as string;
|
const gqlQuery = this.getNodeParameter('query', itemIndex, '') as string;
|
||||||
if (requestMethod === 'GET') {
|
if (requestMethod === 'GET') {
|
||||||
requestOptions.qs = {
|
if (!requestOptions.qs) {
|
||||||
query: gqlQuery,
|
requestOptions.qs = {};
|
||||||
};
|
}
|
||||||
|
requestOptions.qs.query = gqlQuery;
|
||||||
} else {
|
} else {
|
||||||
if (requestFormat === 'json') {
|
if (requestFormat === 'json') {
|
||||||
requestOptions.body = {
|
requestOptions.body = {
|
||||||
|
@ -292,7 +392,15 @@ export class GraphQL implements INodeType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.helpers.request(requestOptions);
|
let response;
|
||||||
|
// Now that the options are all set make the actual http request
|
||||||
|
if (oAuth1Api !== undefined) {
|
||||||
|
response = await this.helpers.requestOAuth1.call(this, 'oAuth1Api', requestOptions);
|
||||||
|
} else if (oAuth2Api !== undefined) {
|
||||||
|
response = await this.helpers.requestOAuth2.call(this, 'oAuth2Api', requestOptions, { tokenType: 'Bearer' });
|
||||||
|
} else {
|
||||||
|
response = await this.helpers.request(requestOptions);
|
||||||
|
}
|
||||||
if (responseFormat === 'string') {
|
if (responseFormat === 'string') {
|
||||||
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue