Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsanv committed Jun 3, 2022
1 parent ac46346 commit b09aa5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
"@types/localtunnel": "^1.9.0",
"@types/lodash.get": "^4.4.6",
"@types/lodash.merge": "^4.6.6",
"@types/lodash.omit": "^4.5.7",
"@types/lodash.set": "^4.3.6",
"@types/lodash.split": "^4.4.7",
"@types/node": "14.17.27",
"@types/open": "^6.1.0",
"@types/parseurl": "^1.3.1",
Expand Down Expand Up @@ -127,6 +130,9 @@
"localtunnel": "^2.0.0",
"lodash.get": "^4.4.2",
"lodash.merge": "^4.6.2",
"lodash.omit": "^4.5.0",
"lodash.set": "^4.3.2",
"lodash.split": "^4.4.2",
"mysql2": "~2.3.0",
"n8n-core": "~0.119.0",
"n8n-editor-ui": "~0.145.0",
Expand All @@ -150,4 +156,4 @@
"validator": "13.7.0",
"winston": "^3.3.3"
}
}
}
40 changes: 20 additions & 20 deletions packages/cli/src/api/oauth2Credential.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ClientOAuth2 from 'client-oauth2';
import Csrf from 'csrf';
import express from 'express';
import _ from 'lodash';
import { get, omit, set, split, unset } from 'lodash';
import { Credentials, UserSettings } from 'n8n-core';
import {
LoggerProxy,
Expand Down Expand Up @@ -102,12 +102,12 @@ oauth2CredentialController.get(
const stateEncodedStr = Buffer.from(JSON.stringify(state)).toString('base64');

const oAuthOptions: ClientOAuth2.Options = {
clientId: _.get(oauthCredentials, 'clientId') as string,
clientSecret: _.get(oauthCredentials, 'clientSecret', '') as string,
accessTokenUri: _.get(oauthCredentials, 'accessTokenUrl', '') as string,
authorizationUri: _.get(oauthCredentials, 'authUrl', '') as string,
clientId: get(oauthCredentials, 'clientId') as string,
clientSecret: get(oauthCredentials, 'clientSecret', '') as string,
accessTokenUri: get(oauthCredentials, 'accessTokenUrl', '') as string,
authorizationUri: get(oauthCredentials, 'authUrl', '') as string,
redirectUri: `${WebhookHelpers.getWebhookBaseUrl()}${restEndpoint}/oauth2-credential/callback`,
scopes: _.split(_.get(oauthCredentials, 'scope', 'openid,') as string, ','),
scopes: split(get(oauthCredentials, 'scope', 'openid,') as string, ','),
state: stateEncodedStr,
};

Expand All @@ -132,14 +132,14 @@ oauth2CredentialController.get(
// Update the credentials in DB
await Db.collections.Credentials.update(req.query.id, newCredentialsData);

const authQueryParameters = _.get(oauthCredentials, 'authQueryParameters', '') as string;
const authQueryParameters = get(oauthCredentials, 'authQueryParameters', '') as string;
let returnUri = oAuthObj.code.getUri();

// if scope uses comma, change it as the library always return then with spaces
if ((_.get(oauthCredentials, 'scope') as string).includes(',')) {
if ((get(oauthCredentials, 'scope') as string).includes(',')) {
const data = querystring.parse(returnUri.split('?')[1]);
data.scope = _.get(oauthCredentials, 'scope') as string;
returnUri = `${_.get(oauthCredentials, 'authUrl', '') as string}?${querystring.stringify(
data.scope = get(oauthCredentials, 'scope') as string;
returnUri = `${get(oauthCredentials, 'authUrl', '') as string}?${querystring.stringify(
data,
)}`;
}
Expand Down Expand Up @@ -252,19 +252,19 @@ oauth2CredentialController.get(
let options = {};

const oAuth2Parameters = {
clientId: _.get(oauthCredentials, 'clientId') as string,
clientSecret: _.get(oauthCredentials, 'clientSecret', '') as string | undefined,
accessTokenUri: _.get(oauthCredentials, 'accessTokenUrl', '') as string,
authorizationUri: _.get(oauthCredentials, 'authUrl', '') as string,
clientId: get(oauthCredentials, 'clientId') as string,
clientSecret: get(oauthCredentials, 'clientSecret', '') as string | undefined,
accessTokenUri: get(oauthCredentials, 'accessTokenUrl', '') as string,
authorizationUri: get(oauthCredentials, 'authUrl', '') as string,
redirectUri: `${WebhookHelpers.getWebhookBaseUrl()}${restEndpoint}/oauth2-credential/callback`,
scopes: _.split(_.get(oauthCredentials, 'scope', 'openid,') as string, ','),
scopes: split(get(oauthCredentials, 'scope', 'openid,') as string, ','),
};

if ((_.get(oauthCredentials, 'authentication', 'header') as string) === 'body') {
if ((get(oauthCredentials, 'authentication', 'header') as string) === 'body') {
options = {
body: {
client_id: _.get(oauthCredentials, 'clientId') as string,
client_secret: _.get(oauthCredentials, 'clientSecret', '') as string,
client_id: get(oauthCredentials, 'clientId') as string,
client_secret: get(oauthCredentials, 'clientSecret', '') as string,
},
};
delete oAuth2Parameters.clientSecret;
Expand All @@ -282,7 +282,7 @@ oauth2CredentialController.get(
);

if (Object.keys(req.query).length > 2) {
_.set(oauthToken.data, 'callbackQueryString', _.omit(req.query, 'state', 'code'));
set(oauthToken.data, 'callbackQueryString', omit(req.query, 'state', 'code'));
}

if (oauthToken === undefined) {
Expand All @@ -307,7 +307,7 @@ oauth2CredentialController.get(
decryptedDataOriginal.oauthTokenData = oauthToken.data;
}

_.unset(decryptedDataOriginal, 'csrfSecret');
unset(decryptedDataOriginal, 'csrfSecret');

const credentials = new Credentials(
credential as INodeCredentialsDetails,
Expand Down

0 comments on commit b09aa5f

Please sign in to comment.