Skip to content

Commit 321bc4d

Browse files
committed
Better 401/403 debugging
1 parent 25bd0e5 commit 321bc4d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

app-routes.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ module.exports = (app) => {
5353
if (req.authUser.isMachine) {
5454
// M2M
5555
if (!req.authUser.scopes || !helper.checkIfExists(def.scopes, req.authUser.scopes)) {
56-
next(new errors.ForbiddenError("You are not allowed to perform this action!"));
56+
next(new errors.ForbiddenError(`You are not allowed to perform this action, because the scopes are incorrect. \
57+
Required scopes: ${JSON.stringify(def.scopes)} \
58+
Provided scopes: ${JSON.stringify(req.authUser.scopes)}`));
5759
} else {
5860
req.authUser.handle = config.M2M_AUDIT_HANDLE;
5961
req.authUser.userId = config.M2M_AUDIT_USERID;
@@ -71,14 +73,17 @@ module.exports = (app) => {
7173
_.map(req.authUser.roles, (r) => r.toLowerCase())
7274
)
7375
) {
74-
next(new errors.ForbiddenError("You are not allowed to perform this action!"));
76+
next(new errors.ForbiddenError(`You are not allowed to perform this action, because the roles are incorrect. \
77+
Required scopes: ${JSON.stringify(def.access)} \
78+
Provided scopes: ${JSON.stringify(req.authUser.roles)}`));
7579
} else {
7680
// user token is used in create/update challenge to ensure user can create/update challenge under specific project
7781
req.userToken = req.headers.authorization.split(" ")[1];
7882
next();
7983
}
8084
} else {
81-
next(new errors.ForbiddenError("You are not authorized to perform this action"));
85+
next(new errors.ForbiddenError("You are not authorized to perform this action, \
86+
because no roles were provided"));
8287
}
8388
}
8489
});

0 commit comments

Comments
 (0)