Skip to content

Commit

Permalink
Add complete function for grants, as has been introduced for main oau…
Browse files Browse the repository at this point in the history
…th2orize.
  • Loading branch information
Samuel Judson committed Mar 7, 2017
1 parent 6338212 commit b3e2c19
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
13 changes: 11 additions & 2 deletions lib/grant/codeIdToken.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions lib/grant/codeIdTokenToken.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions lib/grant/codeToken.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions lib/grant/idToken.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions lib/grant/idTokenToken.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b3e2c19

Please sign in to comment.