From b3e2c19a13004603fd4f8510c56caf351347bc63 Mon Sep 17 00:00:00 2001 From: Samuel Judson Date: Tue, 7 Mar 2017 09:10:34 -0500 Subject: [PATCH] Add complete function for grants, as has been introduced for main oauth2orize. --- lib/grant/codeIdToken.js | 13 +++++++++++-- lib/grant/codeIdTokenToken.js | 14 ++++++++++++-- lib/grant/codeToken.js | 14 ++++++++++++-- lib/grant/idToken.js | 13 +++++++++++-- lib/grant/idTokenToken.js | 13 +++++++++++-- 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/lib/grant/codeIdToken.js b/lib/grant/codeIdToken.js index 947eea1..38f8b5b 100644 --- a/lib/grant/codeIdToken.js +++ b/lib/grant/codeIdToken.js @@ -94,10 +94,16 @@ module.exports = function(options, issueCode, issueIDToken) { * * @param {Object} txn * @param {http.ServerResponse} res + * @param {Function} complete * @param {Function} next * @api public */ - function response(txn, res, next) { + function response(txn, res, complete, next) { + if (next === undefined) { + next = complete; + complete = function(cb) { return cb(); }; + } + var mode = 'fragment' , respond; if (txn.req && txn.req.responseMode) { @@ -131,7 +137,10 @@ module.exports = function(options, issueCode, issueIDToken) { tok['id_token'] = idToken; if (txn.req && txn.req.state) { tok['state'] = txn.req.state; } - return respond(txn, res, tok); + complete(function(err) { + if (err) { return next(err); } + return respond(txn, res, tok); + }); } try { diff --git a/lib/grant/codeIdTokenToken.js b/lib/grant/codeIdTokenToken.js index dd292ee..d99a440 100644 --- a/lib/grant/codeIdTokenToken.js +++ b/lib/grant/codeIdTokenToken.js @@ -97,10 +97,16 @@ module.exports = function(options, issueToken, issueCode, issueIDToken) { * * @param {Object} txn * @param {http.ServerResponse} res + * @param {Function} complete * @param {Function} next * @api public */ - function response(txn, res, next) { + function response(txn, res, complete, next) { + if (next === undefined) { + next = complete; + complete = function(cb) { return cb(); }; + } + var mode = 'fragment' , respond; if (txn.req && txn.req.responseMode) { @@ -132,7 +138,11 @@ module.exports = function(options, issueToken, issueCode, issueIDToken) { if (!idToken) { return next(new AuthorizationError('Request denied by authorization server', 'access_denied')); } tok['id_token'] = idToken; - return respond(txn, res, tok); + + complete(function(err) { + if (err) { return next(err); } + return respond(txn, res, tok); + }); } try { diff --git a/lib/grant/codeToken.js b/lib/grant/codeToken.js index c8cc670..4a31430 100644 --- a/lib/grant/codeToken.js +++ b/lib/grant/codeToken.js @@ -90,10 +90,16 @@ module.exports = function(options, issueToken, issueCode) { * * @param {Object} txn * @param {http.ServerResponse} res + * @param {Function} complete * @param {Function} next * @api public */ - function response(txn, res, next) { + function response(txn, res, complete, next) { + if (next === undefined) { + next = complete; + complete = function(cb) { return cb(); }; + } + var mode = 'fragment' , respond; if (txn.req && txn.req.responseMode) { @@ -125,7 +131,11 @@ module.exports = function(options, issueToken, issueCode) { if (!code) { return next(new AuthorizationError('Request denied by authorization server', 'access_denied')); } tok['code'] = code; - return respond(txn, res, tok); + + complete(function(err) { + if (err) { return next(err); } + return respond(txn, res, tok); + }); } try { diff --git a/lib/grant/idToken.js b/lib/grant/idToken.js index 1b4a1a6..76c828e 100644 --- a/lib/grant/idToken.js +++ b/lib/grant/idToken.js @@ -92,10 +92,16 @@ module.exports = function(options, issue) { * * @param {Object} txn * @param {http.ServerResponse} res + * @param {Function} complete * @param {Function} next * @api public */ - function response(txn, res, next) { + function response(txn, res, complete, next) { + if (next === undefined) { + next = complete; + complete = function(cb) { return cb(); }; + } + var mode = 'fragment' , respond; if (txn.req && txn.req.responseMode) { @@ -129,7 +135,10 @@ module.exports = function(options, issue) { tok['id_token'] = idToken; if (txn.req && txn.req.state) { tok['state'] = txn.req.state; } - return respond(txn, res, tok); + complete(function(err) { + if (err) { return next(err); } + return respond(txn, res, tok); + }); } try { diff --git a/lib/grant/idTokenToken.js b/lib/grant/idTokenToken.js index 313dee4..546dffa 100644 --- a/lib/grant/idTokenToken.js +++ b/lib/grant/idTokenToken.js @@ -94,10 +94,16 @@ module.exports = function(options, issueToken, issueIDToken) { * * @param {Object} txn * @param {http.ServerResponse} res + * @param {Function} complete * @param {Function} next * @api public */ - function response(txn, res, next) { + function response(txn, res, complete, next) { + if (next === undefined) { + next = complete; + complete = function(cb) { return cb(); }; + } + var mode = 'fragment' , respond; @@ -132,7 +138,10 @@ module.exports = function(options, issueToken, issueIDToken) { tok['id_token'] = idToken; if (txn.req && txn.req.state) { tok['state'] = txn.req.state; } - return respond(txn, res, tok); + complete(function(err) { + if (err) { return next(err); } + return respond(txn, res, tok); + }); } try {