Skip to content

Commit 4921a1c

Browse files
authored
fix(handler): deny access when body.allowed is 'false' (#94)
* fix(handler): deny access when body.allowed is 'false' * fix(authorization): use simplified if-branch to check for body allow value
1 parent 9fab017 commit 4921a1c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/handlers/authorize-handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ AuthorizeHandler.prototype.handle = function(request, response) {
7777
throw new InvalidArgumentError('Invalid argument: `response` must be an instance of Response');
7878
}
7979

80-
if ('false' === request.query.allowed) {
80+
if (request.query.allowed === 'false' || request.body.allowed === 'false') {
8181
return Promise.reject(new AccessDeniedError('Access denied: user denied access to application'));
8282
}
8383

test/integration/handlers/authorize-handler_test.js

+18
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,24 @@ describe('AuthorizeHandler integration', function() {
198198
});
199199
});
200200

201+
it('should throw an error if `allowed` is `false` body', function() {
202+
const model = {
203+
getAccessToken: function() {},
204+
getClient: function() {},
205+
saveAuthorizationCode: function() {}
206+
};
207+
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
208+
const request = new Request({ body: { allowed: 'false' }, headers: {}, method: {}, query: {} });
209+
const response = new Response({ body: {}, headers: {} });
210+
211+
return handler.handle(request, response)
212+
.then(should.fail)
213+
.catch(function(e) {
214+
e.should.be.an.instanceOf(AccessDeniedError);
215+
e.message.should.equal('Access denied: user denied access to application');
216+
});
217+
});
218+
201219
it('should redirect to an error response if a non-oauth error is thrown', function() {
202220
const model = {
203221
getAccessToken: function() {

0 commit comments

Comments
 (0)