Skip to content

Commit 339fa82

Browse files
authored
Merge pull request dherault#228 from joubertredrat/custom-authorizer-deny-access
Add support to forbidden access if you deny on custom rule
2 parents 3feaf4b + 356872e commit 339fa82

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/createAuthScheme.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = function createAuthScheme(authFun, authorizerOptions, funName,
3636
const event = {
3737
type: 'TOKEN',
3838
authorizationToken: authorization,
39-
methodArn: `arn:aws:execute-api:${options.region}:<Account id>:<API id>/${options.stage}/${request.method.toUpperCase()}/${endpointPath}`,
39+
methodArn: `arn:aws:execute-api:${options.region}:random-account-id:random-api-id/${options.stage}/${request.method.toUpperCase()}/${endpointPath}`,
4040
};
4141

4242
// Create the Authorization function handler
@@ -72,6 +72,12 @@ module.exports = function createAuthScheme(authFun, authorizerOptions, funName,
7272

7373
serverlessLog(`Authorization function returned a successful response: (λ: ${authFunName})`, policy);
7474

75+
if (policy.policyDocument.Statement[0].Effect === 'Deny') {
76+
serverlessLog(`Authorization response didn't authorize user to access resource: (λ: ${authFunName})`, err);
77+
78+
return reply(Boom.forbidden('User is not authorized to access this resource'));
79+
}
80+
7581
// Set the credentials for the rest of the pipeline
7682
return reply.continue({ credentials: { user: policy.principalId, context: policy.context } });
7783
};

0 commit comments

Comments
 (0)