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:
Rupenieks
2020-07-25 10:09:52 +02:00
committed by GitHub
parent 9c266e7aea
commit 5295696e60
2 changed files with 34 additions and 6 deletions

View File

@@ -188,7 +188,7 @@ export function requestOAuth2(this: IAllExecuteFunctions, credentialsType: strin
* @param {(OptionsWithUrl | requestPromise.RequestPromiseOptions)} requestOptionså
* @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;
if (credentials === undefined) {
@@ -221,14 +221,22 @@ export function requestOAuth1(this: IAllExecuteFunctions, credentialsType: strin
};
const newRequestOptions = {
//@ts-ignore
url: requestOptions.url,
method: requestOptions.method,
data: { ...requestOptions.qs, ...requestOptions.body },
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
newRequestOptions.qs = oauth.authorize(newRequestOptions as RequestOptions, token);
} else {
@@ -698,6 +706,7 @@ export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunEx
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
console.log(requestOptions);
return requestOAuth1.call(this, credentialsType, requestOptions);
},
returnJsonArray,