Skip to content

Commit 5824f79

Browse files
authored
feature(): Supported state in case of denialMerge pull request #99 from FStefanni/issue_89_20_649
Supported state in case of denial
2 parents 52ee11d + 91f27f8 commit 5824f79

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

lib/handlers/authorize-handler.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ AuthorizeHandler.prototype.handle = function(request, response) {
9696
let ResponseType;
9797

9898
return Promise.bind(this)
99+
.then(function() {
100+
state = this.getState(request);
101+
if(request.query.allowed === 'false') {
102+
throw new AccessDeniedError('Access denied: user denied access to application');
103+
}
104+
})
99105
.then(function() {
100106
const requestedScope = this.getScope(request);
101107

@@ -107,7 +113,6 @@ AuthorizeHandler.prototype.handle = function(request, response) {
107113
return this.generateAuthorizationCode(client, user, scope);
108114
})
109115
.then(function(authorizationCode) {
110-
state = this.getState(request);
111116
ResponseType = this.getResponseType(request);
112117

113118
return this.saveAuthorizationCode(authorizationCode, expiresAt, scope, client, uri, user);

test/integration/handlers/authorize-handler_test.js

+27-6
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,33 @@ describe('AuthorizeHandler integration', function() {
161161

162162
it('should throw an error if `allowed` is `false`', function() {
163163
const model = {
164-
getAccessToken: function() {},
165-
getClient: function() {},
166-
saveAuthorizationCode: function() {}
164+
getAccessToken: function() {
165+
return {
166+
user: {},
167+
accessTokenExpiresAt: new Date(new Date().getTime() + 10000)
168+
};
169+
},
170+
getClient: function() {
171+
return { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };
172+
},
173+
saveAuthorizationCode: function() {
174+
throw new Error('Unhandled exception');
175+
}
167176
};
168177
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
169-
const request = new Request({ body: {}, headers: {}, method: {}, query: { allowed: 'false' } });
178+
const request = new Request({
179+
body: {
180+
client_id: 'test'
181+
},
182+
headers: {
183+
'Authorization': 'Bearer foo'
184+
},
185+
method: {},
186+
query: {
187+
allowed: 'false',
188+
state: 'foobar'
189+
}
190+
});
170191
const response = new Response({ body: {}, headers: {} });
171192

172193
return handler.handle(request, response)
@@ -328,7 +349,7 @@ describe('AuthorizeHandler integration', function() {
328349
return handler.handle(request, response)
329350
.then(should.fail)
330351
.catch(function() {
331-
response.get('location').should.equal('http://example.com/cb?error=invalid_scope&error_description=Invalid%20parameter%3A%20%60scope%60');
352+
response.get('location').should.equal('http://example.com/cb?error=invalid_scope&error_description=Invalid%20parameter%3A%20%60scope%60&state=foobar');
332353
});
333354
});
334355

@@ -416,7 +437,7 @@ describe('AuthorizeHandler integration', function() {
416437
return handler.handle(request, response)
417438
.then(should.fail)
418439
.catch(function() {
419-
response.get('location').should.equal('http://example.com/cb?error=invalid_scope&error_description=Invalid%20scope%3A%20Requested%20scope%20is%20invalid');
440+
response.get('location').should.equal('http://example.com/cb?error=invalid_scope&error_description=Invalid%20scope%3A%20Requested%20scope%20is%20invalid&state=foobar');
420441
});
421442
});
422443

0 commit comments

Comments
 (0)