mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-23 11:44:06 -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å
|
||||
* @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,
|
||||
|
|
|
@ -71,6 +71,17 @@ export class HttpRequest implements INodeType {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'oAuth1Api',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'oAuth1',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'oAuth2Api',
|
||||
required: true,
|
||||
|
@ -101,6 +112,10 @@ export class HttpRequest implements INodeType {
|
|||
name: 'Header Auth',
|
||||
value: 'headerAuth'
|
||||
},
|
||||
{
|
||||
name: 'OAuth1',
|
||||
value: 'oAuth1'
|
||||
},
|
||||
{
|
||||
name: 'OAuth2',
|
||||
value: 'oAuth2'
|
||||
|
@ -578,6 +593,7 @@ export class HttpRequest implements INodeType {
|
|||
const httpBasicAuth = this.getCredentials('httpBasicAuth');
|
||||
const httpDigestAuth = this.getCredentials('httpDigestAuth');
|
||||
const httpHeaderAuth = this.getCredentials('httpHeaderAuth');
|
||||
const oAuth1Api = this.getCredentials('oAuth1Api');
|
||||
const oAuth2Api = this.getCredentials('oAuth2Api');
|
||||
|
||||
let requestOptions: OptionsWithUri;
|
||||
|
@ -799,8 +815,11 @@ export class HttpRequest implements INodeType {
|
|||
}
|
||||
try {
|
||||
// Now that the options are all set make the actual http request
|
||||
|
||||
if (oAuth2Api !== undefined) {
|
||||
if (oAuth1Api !== undefined) {
|
||||
//@ts-ignore
|
||||
response = await this.helpers.requestOAuth1.call(this, 'oAuth1Api', requestOptions);
|
||||
}
|
||||
else if (oAuth2Api !== undefined) {
|
||||
//@ts-ignore
|
||||
response = await this.helpers.requestOAuth2.call(this, 'oAuth2Api', requestOptions, 'Bearer');
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue