mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
✨ OAuth1 support for HTTP Request Node (#781)
* Add OAuth1
* ✅ Added OAuth1 support.
Changes to NodeExecuteFunctions:
- Accommodating to use of both a URL and URI property in request options.
- qs if not set is undefined, so checking for its length returns an error
This commit is contained in:
parent
9c266e7aea
commit
5295696e60
|
@ -188,7 +188,7 @@ export function requestOAuth2(this: IAllExecuteFunctions, credentialsType: strin
|
||||||
* @param {(OptionsWithUrl | requestPromise.RequestPromiseOptions)} requestOptionså
|
* @param {(OptionsWithUrl | requestPromise.RequestPromiseOptions)} requestOptionså
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function requestOAuth1(this: IAllExecuteFunctions, credentialsType: string, requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions) {
|
export function requestOAuth1(this: IAllExecuteFunctions, credentialsType: string, requestOptions: OptionsWithUrl | OptionsWithUri | requestPromise.RequestPromiseOptions) {
|
||||||
const credentials = this.getCredentials(credentialsType) as ICredentialDataDecryptedObject;
|
const credentials = this.getCredentials(credentialsType) as ICredentialDataDecryptedObject;
|
||||||
|
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
|
@ -221,14 +221,22 @@ export function requestOAuth1(this: IAllExecuteFunctions, credentialsType: strin
|
||||||
};
|
};
|
||||||
|
|
||||||
const newRequestOptions = {
|
const newRequestOptions = {
|
||||||
//@ts-ignore
|
|
||||||
url: requestOptions.url,
|
|
||||||
method: requestOptions.method,
|
method: requestOptions.method,
|
||||||
data: { ...requestOptions.qs, ...requestOptions.body },
|
data: { ...requestOptions.qs, ...requestOptions.body },
|
||||||
json: requestOptions.json,
|
json: requestOptions.json,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Object.keys(requestOptions.qs).length !== 0) {
|
// Some RequestOptions have a URI and some have a URL
|
||||||
|
//@ts-ignores
|
||||||
|
if (requestOptions.url !== undefined) {
|
||||||
|
//@ts-ignore
|
||||||
|
newRequestOptions.url = requestOptions.url;
|
||||||
|
} else {
|
||||||
|
//@ts-ignore
|
||||||
|
newRequestOptions.url = requestOptions.uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requestOptions.qs !== undefined) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
newRequestOptions.qs = oauth.authorize(newRequestOptions as RequestOptions, token);
|
newRequestOptions.qs = oauth.authorize(newRequestOptions as RequestOptions, token);
|
||||||
} else {
|
} else {
|
||||||
|
@ -698,6 +706,7 @@ export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunEx
|
||||||
return requestOAuth2.call(this, credentialsType, requestOptions, node, additionalData, tokenType, property);
|
return requestOAuth2.call(this, credentialsType, requestOptions, node, additionalData, tokenType, property);
|
||||||
},
|
},
|
||||||
requestOAuth1(this: IAllExecuteFunctions, credentialsType: string, requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions): Promise<any> { // tslint:disable-line:no-any
|
requestOAuth1(this: IAllExecuteFunctions, credentialsType: string, requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
console.log(requestOptions);
|
||||||
return requestOAuth1.call(this, credentialsType, requestOptions);
|
return requestOAuth1.call(this, credentialsType, requestOptions);
|
||||||
},
|
},
|
||||||
returnJsonArray,
|
returnJsonArray,
|
||||||
|
|
|
@ -71,6 +71,17 @@ export class HttpRequest implements INodeType {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'oAuth1Api',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'oAuth1',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'oAuth2Api',
|
name: 'oAuth2Api',
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -101,6 +112,10 @@ export class HttpRequest implements INodeType {
|
||||||
name: 'Header Auth',
|
name: 'Header Auth',
|
||||||
value: 'headerAuth'
|
value: 'headerAuth'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'OAuth1',
|
||||||
|
value: 'oAuth1'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'OAuth2',
|
name: 'OAuth2',
|
||||||
value: 'oAuth2'
|
value: 'oAuth2'
|
||||||
|
@ -578,6 +593,7 @@ export class HttpRequest implements INodeType {
|
||||||
const httpBasicAuth = this.getCredentials('httpBasicAuth');
|
const httpBasicAuth = this.getCredentials('httpBasicAuth');
|
||||||
const httpDigestAuth = this.getCredentials('httpDigestAuth');
|
const httpDigestAuth = this.getCredentials('httpDigestAuth');
|
||||||
const httpHeaderAuth = this.getCredentials('httpHeaderAuth');
|
const httpHeaderAuth = this.getCredentials('httpHeaderAuth');
|
||||||
|
const oAuth1Api = this.getCredentials('oAuth1Api');
|
||||||
const oAuth2Api = this.getCredentials('oAuth2Api');
|
const oAuth2Api = this.getCredentials('oAuth2Api');
|
||||||
|
|
||||||
let requestOptions: OptionsWithUri;
|
let requestOptions: OptionsWithUri;
|
||||||
|
@ -799,8 +815,11 @@ export class HttpRequest implements INodeType {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Now that the options are all set make the actual http request
|
// Now that the options are all set make the actual http request
|
||||||
|
if (oAuth1Api !== undefined) {
|
||||||
if (oAuth2Api !== undefined) {
|
//@ts-ignore
|
||||||
|
response = await this.helpers.requestOAuth1.call(this, 'oAuth1Api', requestOptions);
|
||||||
|
}
|
||||||
|
else if (oAuth2Api !== undefined) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
response = await this.helpers.requestOAuth2.call(this, 'oAuth2Api', requestOptions, 'Bearer');
|
response = await this.helpers.requestOAuth2.call(this, 'oAuth2Api', requestOptions, 'Bearer');
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue