mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Small improvements to ZohoCRM-Node and OAuth fix
This commit is contained in:
parent
f938693695
commit
6a08fc9da3
packages
cli/src
nodes-base
|
@ -955,17 +955,14 @@ class App {
|
||||||
|
|
||||||
let options = {};
|
let options = {};
|
||||||
|
|
||||||
// Here we need a variable that can be set on the credentials
|
if (_.get(oauthCredentials, 'authentication', 'header') as string === 'body') {
|
||||||
// so that base on that include the credentails on the body or
|
options = {
|
||||||
// leave it as default with woukd include the credentails on the header.
|
body: {
|
||||||
// if (thatvariableistrue) {
|
client_id: _.get(oauthCredentials, 'clientId') as string,
|
||||||
// options = {
|
client_secret: _.get(oauthCredentials, 'clientSecret', '') as string,
|
||||||
// body: {
|
},
|
||||||
// client_id: _.get(oauthCredentials, 'clientId') as string,
|
};
|
||||||
// client_secret: _.get(oauthCredentials, 'clientSecret', '') as string,
|
}
|
||||||
// },
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
const oAuthObj = new clientOAuth2({
|
const oAuthObj = new clientOAuth2({
|
||||||
clientId: _.get(oauthCredentials, 'clientId') as string,
|
clientId: _.get(oauthCredentials, 'clientId') as string,
|
||||||
|
|
|
@ -37,5 +37,11 @@ export class GithubOAuth2Api implements ICredentialType {
|
||||||
type: 'hidden' as NodePropertyTypes,
|
type: 'hidden' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'header',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,5 +53,24 @@ export class OAuth2Api implements ICredentialType {
|
||||||
description: 'For some services additional query parameters have to be set which can be defined here.',
|
description: 'For some services additional query parameters have to be set which can be defined here.',
|
||||||
placeholder: 'access_type=offline',
|
placeholder: 'access_type=offline',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'options' as NodePropertyTypes,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Body',
|
||||||
|
value: 'body',
|
||||||
|
description: 'Send credentials in body',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Header',
|
||||||
|
value: 'header',
|
||||||
|
description: 'Send credentials as Basic Auth header',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'header',
|
||||||
|
description: 'Resource to consume.',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,13 @@ export class ZohoOAuth2Api implements ICredentialType {
|
||||||
displayName: 'Auth URI Query Parameters',
|
displayName: 'Auth URI Query Parameters',
|
||||||
name: 'authQueryParameters',
|
name: 'authQueryParameters',
|
||||||
type: 'hidden' as NodePropertyTypes,
|
type: 'hidden' as NodePropertyTypes,
|
||||||
default: 'access_type=online',
|
default: 'access_type=offline',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'body',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,9 @@ import {
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export async function zohoApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function zohoApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
const credentials = this.getCredentials('zohoOAuth2Api');
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
//@ts-ignore
|
|
||||||
Authorization: `Zoho-oauthtoken ${credentials!.oauthTokenData.access_token}`
|
|
||||||
},
|
},
|
||||||
method,
|
method,
|
||||||
body: {
|
body: {
|
||||||
|
|
|
@ -80,12 +80,16 @@ export class ZohoCrm implements INodeType {
|
||||||
// }
|
// }
|
||||||
responseData = await zohoApiRequest.call(this, 'POST', '/leads', body);
|
responseData = await zohoApiRequest.call(this, 'POST', '/leads', body);
|
||||||
responseData = responseData.data;
|
responseData = responseData.data;
|
||||||
|
} else {
|
||||||
|
throw new Error(`The operation "${operation}" is not known!`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(`The resource "${resource}" is not known!`);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Array.isArray(responseData)) {
|
if (Array.isArray(responseData)) {
|
||||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||||
} else {
|
} else if (responseData !== undefined) {
|
||||||
returnData.push(responseData as IDataObject);
|
returnData.push(responseData as IDataObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue