From d262d4f8a0b3651093a37f64de2ece03731a4520 Mon Sep 17 00:00:00 2001 From: Jay Sweeney Date: Fri, 13 Mar 2015 14:51:18 +1000 Subject: [PATCH] Handle passReqToCallback option. --- lib/strategy.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/strategy.js b/lib/strategy.js index dacbf45..3df976d 100644 --- a/lib/strategy.js +++ b/lib/strategy.js @@ -77,7 +77,12 @@ function Strategy(secretOrPublicKey, options, verify) { var strategy = this; - function jwtVerify(token, done) { + function jwtVerify(req, token, done) { + if (!options.passReqToCallback) { + token = arguments[0]; + done = arguments[1]; + req = null; + } jwt.verify(token, secretOrPublicKey, options, function (err, token) { if (err) { if (err instanceof jwt.TokenExpiredError) { @@ -89,11 +94,13 @@ function Strategy(secretOrPublicKey, options, verify) { else { done(err, false); } + } else { + if (options.passReqToCallback) { + verify(req, token, done); + } else { + verify(token, done); + } } - - else - - verify(token, done); }); } HTTPBearerStrategy.call(this, options, jwtVerify);