From ff44a9ca40ae776a686b924ec8a23acd71c98e86 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 8 May 2018 18:43:06 +0530 Subject: [PATCH 1/6] m2m token support --- config/custom-environment-variables.json | 4 ++-- package.json | 2 +- src/util.js | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index 59ff0ddd..b1a48ec5 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -1,5 +1,5 @@ { - "authSecret": "AUTH_SECRET", + "AUTH_SECRET": "AUTH_SECRET", "logLevel": "LOG_LEVEL", "version": "APP_VERSION", "captureLogs": "CAPTURE_LOGS", @@ -37,7 +37,7 @@ "minPoolSize": "DB_MIN_POOL_SIZE" }, "analyticsKey": "ANALYTICS_KEY", - "validIssuers": "VALID_ISSUERS", + "VALID_ISSUERS": "VALID_ISSUERS", "jwksUri": "JWKS_URI", "busApiUrl": "BUS_API_URL", "busApiToken": "BUS_API_TOKEN" diff --git a/package.json b/package.json index b6234466..39665962 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "pg": "^4.5.5", "pg-native": "^1.10.0", "sequelize": "^3.23.0", - "tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.2", + "tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.3", "traverse": "^0.6.6", "urlencode": "^1.1.0" }, diff --git a/src/util.js b/src/util.js index 6371f726..0c4a1d1c 100644 --- a/src/util.js +++ b/src/util.js @@ -70,6 +70,8 @@ _.assignIn(util, { * @return {boolean} true/false */ hasRole: (req, role) => { + let isMachineToken = _.get(req, 'authUser.isMachine', false); + if (isMachineToken) return true; let roles = _.get(req, 'authUser.roles', []); roles = roles.map(s => s.toLowerCase()); return _.indexOf(roles, role.toLowerCase()) >= 0; @@ -81,6 +83,8 @@ _.assignIn(util, { * @return {boolean} true/false */ hasRoles: (req, roles) => { + let isMachineToken = _.get(req, 'authUser.isMachine', false); + if (isMachineToken) return true; let authRoles = _.get(req, 'authUser.roles', []); authRoles = authRoles.map(s => s.toLowerCase()); return _.intersection(authRoles, roles.map(r => r.toLowerCase())).length > 0; @@ -101,6 +105,8 @@ _.assignIn(util, { * @return {boolean} true/false */ hasAdminRole: (req) => { + let isMachineToken = _.get(req, 'authUser.isMachine', false); + if (isMachineToken) return true; let roles = _.get(req, 'authUser.roles', []); roles = roles.map(s => s.toLowerCase()); return _.intersection(roles, ADMIN_ROLES.map(r => r.toLowerCase())).length > 0; From 33d6b1ce4c8b189ff96afcf8fc9333c8b032c5cf Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Wed, 9 May 2018 14:08:17 +0530 Subject: [PATCH 2/6] fixing lint error. --- src/util.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util.js b/src/util.js index 0c4a1d1c..399e119c 100644 --- a/src/util.js +++ b/src/util.js @@ -70,7 +70,7 @@ _.assignIn(util, { * @return {boolean} true/false */ hasRole: (req, role) => { - let isMachineToken = _.get(req, 'authUser.isMachine', false); + const isMachineToken = _.get(req, 'authUser.isMachine', false); if (isMachineToken) return true; let roles = _.get(req, 'authUser.roles', []); roles = roles.map(s => s.toLowerCase()); @@ -83,7 +83,7 @@ _.assignIn(util, { * @return {boolean} true/false */ hasRoles: (req, roles) => { - let isMachineToken = _.get(req, 'authUser.isMachine', false); + const isMachineToken = _.get(req, 'authUser.isMachine', false); if (isMachineToken) return true; let authRoles = _.get(req, 'authUser.roles', []); authRoles = authRoles.map(s => s.toLowerCase()); @@ -105,7 +105,7 @@ _.assignIn(util, { * @return {boolean} true/false */ hasAdminRole: (req) => { - let isMachineToken = _.get(req, 'authUser.isMachine', false); + const isMachineToken = _.get(req, 'authUser.isMachine', false); if (isMachineToken) return true; let roles = _.get(req, 'authUser.roles', []); roles = roles.map(s => s.toLowerCase()); From a6e7fecb865f86efcfe59ef51354547db2c25ed6 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Wed, 9 May 2018 14:20:14 +0530 Subject: [PATCH 3/6] env variables name change and clean-up to tc-core v2.3 accordingly. --- config/default.json | 6 ++---- config/development.json | 1 - config/test.json | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/config/default.json b/config/default.json index dd753d8e..7ec4c742 100644 --- a/config/default.json +++ b/config/default.json @@ -1,6 +1,5 @@ { - "authSecret": "secret", - "authDomain": "topcoder-dev.com", + "AUTH_SECRET": "secret", "logLevel": "info", "version": "v4", "captureLogs": "false", @@ -42,8 +41,7 @@ "idleTimeout": 1000 }, "analyticsKey": "", - "validIssuers": "[\"https:\/\/topcoder-newauth.auth0.com\/\",\"https:\/\/api.topcoder-dev.com\"]", - "jwksUri": "", + "VALID_ISSUERS": "[\"https:\/\/topcoder-newauth.auth0.com\/\",\"https:\/\/api.topcoder-dev.com\"]", "busApiUrl": "http://api.topcoder-dev.com", "busApiToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoicHJvamVjdC1zZXJ2aWNlIiwiaWF0IjoxNTEyNzQ3MDgyLCJleHAiOjE1MjEzODcwODJ9.PHuNcFDaotGAL8RhQXQMdpL8yOKXxjB5DbBIodmt7RE" } diff --git a/config/development.json b/config/development.json index b7de350a..7e8ce29d 100644 --- a/config/development.json +++ b/config/development.json @@ -1,5 +1,4 @@ { - "authDomain": "topcoder-dev.com", "pubsubQueueName": "dev.project.service", "pubsubExchangeName": "dev.projects", "attachmentsS3Bucket": "topcoder-dev-media" diff --git a/config/test.json b/config/test.json index 2b045431..26d22a7a 100644 --- a/config/test.json +++ b/config/test.json @@ -1,6 +1,5 @@ { - "authSecret": "secret", - "authDomain": "topcoder-dev.com", + "AUTH_SECRET": "secret", "logLevel": "debug", "captureLogs": "false", "logentriesToken": "", From ca54392416f596e4f9946c20a8d29bd60d491182 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Wed, 9 May 2018 15:15:03 +0530 Subject: [PATCH 4/6] temp off for testing.. --- src/routes/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/index.js b/src/routes/index.js index 16018aef..6adf59e7 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -94,7 +94,7 @@ router.use((err, req, res, next) => { // eslint-disable-line no-unused-vars } const rerr = err; rerr.status = rerr.status || 500; - req.log.error(rerr); + //req.log.error(rerr); res.status(rerr.status).send(body); }); From 541cd13e971f6feed4403cc48de8645eb7bd1e15 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Wed, 9 May 2018 15:19:47 +0530 Subject: [PATCH 5/6] fix lint issue. --- src/routes/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/index.js b/src/routes/index.js index 6adf59e7..7fe8de11 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -94,7 +94,7 @@ router.use((err, req, res, next) => { // eslint-disable-line no-unused-vars } const rerr = err; rerr.status = rerr.status || 500; - //req.log.error(rerr); + // req.log.error(rerr); res.status(rerr.status).send(body); }); From 94fb783ae26d008f668908c9f6ea575497d840de Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Wed, 9 May 2018 15:39:07 +0530 Subject: [PATCH 6/6] reverting temp fix. --- src/routes/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/index.js b/src/routes/index.js index 7fe8de11..16018aef 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -94,7 +94,7 @@ router.use((err, req, res, next) => { // eslint-disable-line no-unused-vars } const rerr = err; rerr.status = rerr.status || 500; - // req.log.error(rerr); + req.log.error(rerr); res.status(rerr.status).send(body); });