diff --git a/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts index 830eff470c..c3ed803d3f 100644 --- a/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts @@ -87,6 +87,8 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa const now = moment().unix(); + const privateKey = (credentials.privateKey as string).replace(/\\n/g, '\n'); + const signature = jwt.sign( { 'iss': credentials.email as string, @@ -96,11 +98,11 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa 'iat': now, 'exp': now + 3600, }, - credentials.privateKey as string, + privateKey as string, { algorithm: 'RS256', header: { - 'kid': credentials.privateKey as string, + 'kid': privateKey as string, 'typ': 'JWT', 'alg': 'RS256', }, diff --git a/packages/nodes-base/nodes/Google/Docs/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Docs/GenericFunctions.ts index 736845d2dc..7e64e27946 100644 --- a/packages/nodes-base/nodes/Google/Docs/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Docs/GenericFunctions.ts @@ -95,6 +95,8 @@ function getAccessToken(this: IExecuteFunctions | ILoadOptionsFunctions, credent const now = moment().unix(); + const privateKey = (credentials.privateKey as string).replace(/\\n/g, '\n'); + const signature = jwt.sign( { 'iss': credentials.email as string, @@ -104,11 +106,11 @@ function getAccessToken(this: IExecuteFunctions | ILoadOptionsFunctions, credent 'iat': now, 'exp': now + 3600, }, - credentials.privateKey as string, + privateKey as string, { algorithm: 'RS256', header: { - 'kid': credentials.privateKey as string, + 'kid': privateKey as string, 'typ': 'JWT', 'alg': 'RS256', }, diff --git a/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts index 185e00da2b..d762a5f075 100644 --- a/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts @@ -32,7 +32,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF uri: uri || `https://www.googleapis.com${resource}`, json: true, }; - + options = Object.assign({}, options, option); try { @@ -94,6 +94,8 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa const now = moment().unix(); + const privateKey = (credentials.privateKey as string).replace(/\\n/g, '\n'); + const signature = jwt.sign( { 'iss': credentials.email as string, @@ -103,11 +105,11 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa 'iat': now, 'exp': now + 3600, }, - credentials.privateKey as string, + privateKey as string, { algorithm: 'RS256', header: { - 'kid': credentials.privateKey as string, + 'kid': privateKey as string, 'typ': 'JWT', 'alg': 'RS256', }, diff --git a/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts index 3301d5731f..353cbf5f95 100644 --- a/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts @@ -216,6 +216,8 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa const now = moment().unix(); + const privateKey = (credentials.privateKey as string).replace(/\\n/g, '\n'); + const signature = jwt.sign( { 'iss': credentials.email as string, @@ -225,11 +227,11 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa 'iat': now, 'exp': now + 3600, }, - credentials.privateKey as string, + privateKey, { algorithm: 'RS256', header: { - 'kid': credentials.privateKey as string, + 'kid': privateKey, 'typ': 'JWT', 'alg': 'RS256', }, @@ -252,4 +254,3 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa //@ts-ignore return this.helpers.request(options); } - diff --git a/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts index bd5113d827..96d8a6530e 100644 --- a/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts @@ -93,6 +93,8 @@ export function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions const now = moment().unix(); + const privateKey = (credentials.privateKey as string).replace(/\\n/g, '\n'); + const signature = jwt.sign( { 'iss': credentials.email as string, @@ -102,11 +104,11 @@ export function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions 'iat': now, 'exp': now + 3600, }, - credentials.privateKey as string, + privateKey, { algorithm: 'RS256', header: { - 'kid': credentials.privateKey as string, + 'kid': privateKey, 'typ': 'JWT', 'alg': 'RS256', }, diff --git a/packages/nodes-base/nodes/Google/Slides/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Slides/GenericFunctions.ts index 245cc2467a..71f9505685 100644 --- a/packages/nodes-base/nodes/Google/Slides/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Slides/GenericFunctions.ts @@ -8,6 +8,7 @@ import { } from 'n8n-core'; import { + ICredentialDataDecryptedObject, IDataObject, NodeApiError, } from 'n8n-workflow'; @@ -64,7 +65,7 @@ export async function googleApiRequest( function getAccessToken( this: IExecuteFunctions | ILoadOptionsFunctions, - { email, privateKey }: { email: string, privateKey: string }, + credentials: ICredentialDataDecryptedObject, ) { // https://developers.google.com/identity/protocols/oauth2/service-account#httprest @@ -75,10 +76,12 @@ function getAccessToken( const now = moment().unix(); + const privateKey = (credentials.privateKey as string).replace(/\\n/g, '\n'); + const signature = jwt.sign( { - iss: email, - sub: email, + iss: credentials.email, + sub: credentials.email, scope: scopes.join(' '), aud: 'https://oauth2.googleapis.com/token', iat: now, diff --git a/packages/nodes-base/nodes/Google/Translate/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Translate/GenericFunctions.ts index ec5bbaf273..5bc3b98310 100644 --- a/packages/nodes-base/nodes/Google/Translate/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Translate/GenericFunctions.ts @@ -86,6 +86,8 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa const now = moment().unix(); + const privateKey = (credentials.privateKey as string).replace(/\\n/g, '\n'); + const signature = jwt.sign( { 'iss': credentials.email as string, @@ -95,11 +97,11 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa 'iat': now, 'exp': now + 3600, }, - credentials.privateKey as string, + privateKey as string, { algorithm: 'RS256', header: { - 'kid': credentials.privateKey as string, + 'kid': privateKey as string, 'typ': 'JWT', 'alg': 'RS256', },