From 9c75e1d110c4a6bcb592454d63b80af9a7f0dcb1 Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 15 Mar 2023 16:50:11 +0100 Subject: [PATCH] remove querystring dependency --- .../credentials/credentials.helperFunctions.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/credentials/credentials.helperFunctions.ts b/packages/cli/src/credentials/credentials.helperFunctions.ts index b8d74207a86cc..04ddb3bbf4640 100644 --- a/packages/cli/src/credentials/credentials.helperFunctions.ts +++ b/packages/cli/src/credentials/credentials.helperFunctions.ts @@ -1,4 +1,3 @@ -import querystring from 'querystring'; import type { AxiosResponse } from 'axios'; import axios from 'axios'; import type { IDataObject } from 'n8n-workflow'; @@ -133,7 +132,11 @@ export function getUri(options: OAuth2Parameters, tokenType: string) { } const sep = options.authorizationUri.includes('?') ? '&' : '?'; - return options.authorizationUri + sep + querystring.stringify(Object.assign(qs, options.query)); + return ( + options.authorizationUri + + sep + + new URLSearchParams(Object.assign(qs, options.query) as Record).toString() + ); } export async function request(options: IDataObject) { @@ -186,15 +189,17 @@ export async function getToken( } const data = - typeof url.search === 'string' ? querystring.parse(url.search.substr(1)) : url.search || {}; + typeof url.search === 'string' + ? Object.fromEntries(new URLSearchParams(url.search.substr(1))) + : url.search || {}; const error = getAuthError(data); if (error) { return Promise.reject(error); } - if (options.state !== null && data.state !== options.state) { - return Promise.reject(new TypeError(`Invalid state: ${data.state as string}`)); + if (options.state && data.state !== options.state) { + return Promise.reject(new TypeError(`Invalid state: ${data.state}`)); } // Check whether the response code is set.