Skip to content

Commit f1c4fed

Browse files
author
sachin-maheshwari
authored
Merge pull request topcoder-platform#77 from topcoder-platform/revert-75-revert-74-feature/m2m-token
Reapplying "m2m token support"
2 parents e588e91 + af165c3 commit f1c4fed

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

config/custom-environment-variables.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"authSecret": "AUTH_SECRET",
2+
"AUTH_SECRET": "AUTH_SECRET",
33
"logLevel": "LOG_LEVEL",
44
"version": "APP_VERSION",
55
"captureLogs": "CAPTURE_LOGS",
@@ -37,7 +37,7 @@
3737
"minPoolSize": "DB_MIN_POOL_SIZE"
3838
},
3939
"analyticsKey": "ANALYTICS_KEY",
40-
"validIssuers": "VALID_ISSUERS",
40+
"VALID_ISSUERS": "VALID_ISSUERS",
4141
"jwksUri": "JWKS_URI",
4242
"busApiUrl": "BUS_API_URL",
4343
"busApiToken": "BUS_API_TOKEN"

config/default.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"authSecret": "secret",
3-
"authDomain": "topcoder-dev.com",
2+
"AUTH_SECRET": "secret",
43
"logLevel": "info",
54
"version": "v4",
65
"captureLogs": "false",
@@ -42,8 +41,7 @@
4241
"idleTimeout": 1000
4342
},
4443
"analyticsKey": "",
45-
"validIssuers": "[\"https:\/\/topcoder-newauth.auth0.com\/\",\"https:\/\/api.topcoder-dev.com\"]",
46-
"jwksUri": "",
44+
"VALID_ISSUERS": "[\"https:\/\/topcoder-newauth.auth0.com\/\",\"https:\/\/api.topcoder-dev.com\"]",
4745
"busApiUrl": "http://api.topcoder-dev.com",
4846
"busApiToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoicHJvamVjdC1zZXJ2aWNlIiwiaWF0IjoxNTEyNzQ3MDgyLCJleHAiOjE1MjEzODcwODJ9.PHuNcFDaotGAL8RhQXQMdpL8yOKXxjB5DbBIodmt7RE",
4947
"HEALTH_CHECK_URL": "_health"

config/development.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"authDomain": "topcoder-dev.com",
32
"pubsubQueueName": "dev.project.service",
43
"pubsubExchangeName": "dev.projects",
54
"attachmentsS3Bucket": "topcoder-dev-media"

config/test.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"authSecret": "secret",
3-
"authDomain": "topcoder-dev.com",
2+
"AUTH_SECRET": "secret",
43
"logLevel": "debug",
54
"captureLogs": "false",
65
"logentriesToken": "",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"pg": "^4.5.5",
5656
"pg-native": "^1.10.0",
5757
"sequelize": "^3.23.0",
58-
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.2",
58+
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.3",
5959
"traverse": "^0.6.6",
6060
"urlencode": "^1.1.0"
6161
},

src/util.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ _.assignIn(util, {
7070
* @return {boolean} true/false
7171
*/
7272
hasRole: (req, role) => {
73+
const isMachineToken = _.get(req, 'authUser.isMachine', false);
74+
if (isMachineToken) return true;
7375
let roles = _.get(req, 'authUser.roles', []);
7476
roles = roles.map(s => s.toLowerCase());
7577
return _.indexOf(roles, role.toLowerCase()) >= 0;
@@ -81,6 +83,8 @@ _.assignIn(util, {
8183
* @return {boolean} true/false
8284
*/
8385
hasRoles: (req, roles) => {
86+
const isMachineToken = _.get(req, 'authUser.isMachine', false);
87+
if (isMachineToken) return true;
8488
let authRoles = _.get(req, 'authUser.roles', []);
8589
authRoles = authRoles.map(s => s.toLowerCase());
8690
return _.intersection(authRoles, roles.map(r => r.toLowerCase())).length > 0;
@@ -101,6 +105,8 @@ _.assignIn(util, {
101105
* @return {boolean} true/false
102106
*/
103107
hasAdminRole: (req) => {
108+
const isMachineToken = _.get(req, 'authUser.isMachine', false);
109+
if (isMachineToken) return true;
104110
let roles = _.get(req, 'authUser.roles', []);
105111
roles = roles.map(s => s.toLowerCase());
106112
return _.intersection(roles, ADMIN_ROLES.map(r => r.toLowerCase())).length > 0;

0 commit comments

Comments
 (0)