From 53de4e2532ac37cc742d4f51e7f578131a50684b Mon Sep 17 00:00:00 2001 From: Christian Tellnes Date: Sat, 7 Feb 2015 00:27:36 +0100 Subject: [PATCH] pass request to immediate callback fixes #98 --- lib/middleware/authorization.js | 2 + .../authorization.immediate.test.js | 47 ++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/middleware/authorization.js b/lib/middleware/authorization.js index 91e91c3f..65ecfcf6 100644 --- a/lib/middleware/authorization.js +++ b/lib/middleware/authorization.js @@ -191,6 +191,8 @@ module.exports = function(server, options, validate, immediate) { var arity = immediate.length; if (arity == 4) { immediate(req.oauth2.client, req.oauth2.user, req.oauth2.req.scope, immediated); + } else if (arity === 5) { + immediate(req, req.oauth2.client, req.oauth2.user, req.oauth2.req.scope, immediated); } else { // arity == 3 immediate(req.oauth2.client, req.oauth2.user, immediated); } diff --git a/test/middleware/authorization.immediate.test.js b/test/middleware/authorization.immediate.test.js index 65b4d23e..9ae01449 100644 --- a/test/middleware/authorization.immediate.test.js +++ b/test/middleware/authorization.immediate.test.js @@ -296,5 +296,50 @@ describe('authorization', function() { }); }); }); - + + describe('immediate callback with scope and req', function() { + function immediate(req, client, user, scope, done) { + expect(req.query.immediate).to.be.true; + if (client.id == '1234' && user.id == 'u123' && scope == 'profile') { + return done(null, true, { scope: 'read' }); + } + return done(new Error('something went wrong while checking immediate status')); + } + + describe('handling a request that is immediately authorized', function() { + var request, response, err; + + before(function(done) { + chai.connect.use('express', authorization(server, validate, immediate)) + .req(function(req) { + request = req; + req.query = { response_type: 'code', client_id: '1234', redirect_uri: 'http://example.com/auth/callback', scope: 'profile', immediate: true }; + req.session = {}; + req.user = { id: 'u123' }; + }) + .end(function(res) { + response = res; + done(); + }) + .dispatch(); + }); + + it('should not error', function() { + expect(err).to.be.undefined; + }); + + it('should respond', function() { + expect(response.getHeader('Location')).to.equal('http://example.com/auth/callback'); + }); + + it('should add transaction', function() { + expect(request.oauth2).to.be.an('object'); + }); + + it('should not store transaction in session', function() { + expect(request.session['authorize']).to.be.undefined; + }); + }); + }); + });