From 6ed02322f9d57e1c783261e7529cef4e1f5a9522 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Fri, 11 Jan 2019 17:53:26 +0530 Subject: [PATCH 1/6] m2m token through auth0 proxy server. --- package.json | 2 +- src/common/helper.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 43d1dfa..6b13fb2 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "joi": "^13.4.0", "lodash": "^4.17.10", "superagent": "^3.8.3", - "tc-core-library-js": "appirio-tech/tc-core-library-js.git#feature/m2mtoken" + "tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6" }, "devDependencies": { "chai": "^4.2.0", diff --git a/src/common/helper.js b/src/common/helper.js index ddea845..671543d 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -2,13 +2,13 @@ const m2mAuth = require('tc-core-library-js').auth.m2m const request = require('superagent') const _ = require('lodash') +const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL'])) /* * Function to get M2M token * @returns {Promise} */ const getM2Mtoken = async (config) => { - const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME'])) return m2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET) } From f0aecdefeeb21e311943d63faf146c423cd5475e Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 15 Jan 2019 16:38:23 +0530 Subject: [PATCH 2/6] fixing schema validation issue for auth0 proxy url. --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index eabb21c..f746a19 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,8 @@ module.exports = (config) => { AUTH0_CLIENT_ID: joi.string().required(), AUTH0_CLIENT_SECRET: joi.string().required(), BUSAPI_URL: joi.string().uri().trim().required(), - KAFKA_ERROR_TOPIC: joi.string().required() + KAFKA_ERROR_TOPIC: joi.string().required(), + AUTH0_PROXY_SERVER_URL: joi.string() }) // Validate the arguments From 4b1fb5a8c12049be270621815375f77b85dc05fb Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 15 Jan 2019 18:06:40 +0530 Subject: [PATCH 3/6] to avoid multiple auth0 calls, trying this way. --- src/common/helper.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/helper.js b/src/common/helper.js index 671543d..5c0b013 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -2,13 +2,16 @@ const m2mAuth = require('tc-core-library-js').auth.m2m const request = require('superagent') const _ = require('lodash') -const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL'])) +var m2m = null /* * Function to get M2M token * @returns {Promise} */ const getM2Mtoken = async (config) => { + if (_.isNull(m2m)) { + m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL'])) + } return m2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET) } From a9eadbe3a8abbbba1359fdaaf6696c0dd273a6fb Mon Sep 17 00:00:00 2001 From: sachin-maheshwari Date: Mon, 4 Feb 2019 18:26:33 +0530 Subject: [PATCH 4/6] Update helper.js reverting my changes for excess call, fixing in core lib. --- src/common/helper.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/common/helper.js b/src/common/helper.js index 5c0b013..671543d 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -2,16 +2,13 @@ const m2mAuth = require('tc-core-library-js').auth.m2m const request = require('superagent') const _ = require('lodash') -var m2m = null +const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL'])) /* * Function to get M2M token * @returns {Promise} */ const getM2Mtoken = async (config) => { - if (_.isNull(m2m)) { - m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL'])) - } return m2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET) } From 90300992304635497a13a55f0fa82f3b94c9e7cb Mon Sep 17 00:00:00 2001 From: sachin-maheshwari Date: Mon, 4 Feb 2019 18:38:47 +0530 Subject: [PATCH 5/6] Update helper.js typo --- src/common/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/helper.js b/src/common/helper.js index 671543d..c0fe14c 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -2,13 +2,13 @@ const m2mAuth = require('tc-core-library-js').auth.m2m const request = require('superagent') const _ = require('lodash') -const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL'])) /* * Function to get M2M token * @returns {Promise} */ const getM2Mtoken = async (config) => { + const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL'])) return m2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET) } From db1b5b9774ec994657f6f02e3d12b4bd8b679aaf Mon Sep 17 00:00:00 2001 From: sachin-maheshwari Date: Mon, 4 Feb 2019 18:57:50 +0530 Subject: [PATCH 6/6] Update helper.js changes required to avoid excess auth0 calls. --- src/common/helper.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/helper.js b/src/common/helper.js index c0fe14c..5c0b013 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -2,13 +2,16 @@ const m2mAuth = require('tc-core-library-js').auth.m2m const request = require('superagent') const _ = require('lodash') +var m2m = null /* * Function to get M2M token * @returns {Promise} */ const getM2Mtoken = async (config) => { - const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL'])) + if (_.isNull(m2m)) { + m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL'])) + } return m2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET) }