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/config/default.json b/config/default.json index 167c89b5..32a3a965 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", "HEALTH_CHECK_URL": "_health" 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": "", 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..399e119c 100644 --- a/src/util.js +++ b/src/util.js @@ -70,6 +70,8 @@ _.assignIn(util, { * @return {boolean} true/false */ hasRole: (req, role) => { + const 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) => { + const 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) => { + const 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;