Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 5723b79

Browse files
authored
Merge pull request #145 from topcoder-platform/issue-144
Add support for allowAnonymous flag on endpoints
2 parents 7a1d0ba + c98a0ce commit 5723b79

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

package-lock.json

Lines changed: 34 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ _.forEach(routes, (verbs, path) => {
4040
throw new Error(`${def.method} is undefined`);
4141
}
4242
const actions = [];
43-
actions.push((req, res, next) => {
44-
const v3jwt = _.get(req.cookies, constants.JWT_V3_NAME);
45-
if (v3jwt) {
46-
const decoded = jwtDecode(v3jwt);
47-
req.currentUser = {
48-
handle: decoded.handle.toLowerCase(),
49-
roles: decoded.roles,
50-
};
51-
}
52-
req.signature = `${def.controller}#${def.method}`;
53-
next();
54-
});
43+
if (!def.allowAnonymous) {
44+
actions.push((req, res, next) => {
45+
const v3jwt = _.get(req.cookies, constants.JWT_V3_NAME);
46+
if (v3jwt) {
47+
const decoded = jwtDecode(v3jwt);
48+
req.currentUser = {
49+
handle: decoded.handle.toLowerCase(),
50+
roles: decoded.roles,
51+
};
52+
}
53+
req.signature = `${def.controller}#${def.method}`;
54+
next();
55+
});
56+
}
5557
if (def.tcLogin) {
5658
// middleware to handle TC login
5759
actions.push((req, res, next) => {

src/routes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ module.exports = {
4343
method: 'addUserToTeam',
4444
allowNormalUser: true,
4545
tcLogin: true,
46+
allowAnonymous: true,
4647
},
4748
},
4849
'/github/normaluser/callback': {
4950
get: {
5051
controller: 'GithubController',
5152
method: 'addUserToTeamCallback',
5253
allowNormalUser: true,
54+
allowAnonymous: true,
5355
},
5456
},
5557

@@ -84,13 +86,15 @@ module.exports = {
8486
method: 'addUserToGroup',
8587
allowNormalUser: true,
8688
tcLogin: true,
89+
allowAnonymous: true,
8790
},
8891
},
8992
'/gitlab/normaluser/callback': {
9093
get: {
9194
controller: 'GitlabController',
9295
method: 'addUserToGroupCallback',
9396
allowNormalUser: true,
97+
allowAnonymous: true,
9498
},
9599
},
96100

0 commit comments

Comments
 (0)