Skip to content

Commit 53de4e2

Browse files
committed
pass request to immediate callback
fixes jaredhanson#98
1 parent b30ac84 commit 53de4e2

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

lib/middleware/authorization.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ module.exports = function(server, options, validate, immediate) {
191191
var arity = immediate.length;
192192
if (arity == 4) {
193193
immediate(req.oauth2.client, req.oauth2.user, req.oauth2.req.scope, immediated);
194+
} else if (arity === 5) {
195+
immediate(req, req.oauth2.client, req.oauth2.user, req.oauth2.req.scope, immediated);
194196
} else { // arity == 3
195197
immediate(req.oauth2.client, req.oauth2.user, immediated);
196198
}

test/middleware/authorization.immediate.test.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,5 +296,50 @@ describe('authorization', function() {
296296
});
297297
});
298298
});
299-
299+
300+
describe('immediate callback with scope and req', function() {
301+
function immediate(req, client, user, scope, done) {
302+
expect(req.query.immediate).to.be.true;
303+
if (client.id == '1234' && user.id == 'u123' && scope == 'profile') {
304+
return done(null, true, { scope: 'read' });
305+
}
306+
return done(new Error('something went wrong while checking immediate status'));
307+
}
308+
309+
describe('handling a request that is immediately authorized', function() {
310+
var request, response, err;
311+
312+
before(function(done) {
313+
chai.connect.use('express', authorization(server, validate, immediate))
314+
.req(function(req) {
315+
request = req;
316+
req.query = { response_type: 'code', client_id: '1234', redirect_uri: 'http://example.com/auth/callback', scope: 'profile', immediate: true };
317+
req.session = {};
318+
req.user = { id: 'u123' };
319+
})
320+
.end(function(res) {
321+
response = res;
322+
done();
323+
})
324+
.dispatch();
325+
});
326+
327+
it('should not error', function() {
328+
expect(err).to.be.undefined;
329+
});
330+
331+
it('should respond', function() {
332+
expect(response.getHeader('Location')).to.equal('http://example.com/auth/callback');
333+
});
334+
335+
it('should add transaction', function() {
336+
expect(request.oauth2).to.be.an('object');
337+
});
338+
339+
it('should not store transaction in session', function() {
340+
expect(request.session['authorize']).to.be.undefined;
341+
});
342+
});
343+
});
344+
300345
});

0 commit comments

Comments
 (0)