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

Add support for allowAnonymous flag on endpoints #145

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ _.forEach(routes, (verbs, path) => {
throw new Error(`${def.method} is undefined`);
}
const actions = [];
actions.push((req, res, next) => {
const v3jwt = _.get(req.cookies, constants.JWT_V3_NAME);
if (v3jwt) {
const decoded = jwtDecode(v3jwt);
req.currentUser = {
handle: decoded.handle.toLowerCase(),
roles: decoded.roles,
};
}
req.signature = `${def.controller}#${def.method}`;
next();
});
if (!def.allowAnonymous) {
actions.push((req, res, next) => {
const v3jwt = _.get(req.cookies, constants.JWT_V3_NAME);
if (v3jwt) {
const decoded = jwtDecode(v3jwt);
req.currentUser = {
handle: decoded.handle.toLowerCase(),
roles: decoded.roles,
};
}
req.signature = `${def.controller}#${def.method}`;
next();
});
}
if (def.tcLogin) {
// middleware to handle TC login
actions.push((req, res, next) => {
Expand Down
4 changes: 4 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ module.exports = {
method: 'addUserToTeam',
allowNormalUser: true,
tcLogin: true,
allowAnonymous: true,
},
},
'/github/normaluser/callback': {
get: {
controller: 'GithubController',
method: 'addUserToTeamCallback',
allowNormalUser: true,
allowAnonymous: true,
},
},

Expand Down Expand Up @@ -84,13 +86,15 @@ module.exports = {
method: 'addUserToGroup',
allowNormalUser: true,
tcLogin: true,
allowAnonymous: true,
},
},
'/gitlab/normaluser/callback': {
get: {
controller: 'GitlabController',
method: 'addUserToGroupCallback',
allowNormalUser: true,
allowAnonymous: true,
},
},

Expand Down