From 630d2ca926bbd5fab3b4cea79e5030d010711129 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 23 Aug 2021 15:52:49 +0200 Subject: [PATCH] Give passport verfiy callback wrapper the same arity as the original callback passed in via options --- .../@node-red/editor-api/lib/auth/index.js | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/node_modules/@node-red/editor-api/lib/auth/index.js b/packages/node_modules/@node-red/editor-api/lib/auth/index.js index fb95ede7b..5552301d0 100644 --- a/packages/node_modules/@node-red/editor-api/lib/auth/index.js +++ b/packages/node_modules/@node-red/editor-api/lib/auth/index.js @@ -173,27 +173,30 @@ function genericStrategy(adminApp,strategy) { adminApp.use(passport.session()); var options = strategy.options; + var verify = function() { + var originalDone = arguments[arguments.length-1]; + if (options.verify) { + var args = Array.from(arguments); + args[args.length-1] = function(err,profile) { + if (err) { + return originalDone(err); + } else { + return completeVerify(profile,originalDone); + } + }; - passport.use(new strategy.strategy(options, - function() { - var originalDone = arguments[arguments.length-1]; - if (options.verify) { - var args = Array.from(arguments); - args[args.length-1] = function(err,profile) { - if (err) { - return originalDone(err); - } else { - return completeVerify(profile,originalDone); - } - }; - options.verify.apply(null,args); - } else { - var profile = arguments[arguments.length - 2]; - return completeVerify(profile,originalDone); - } - + options.verify.apply(null,args); + } else { + var profile = arguments[arguments.length - 2]; + return completeVerify(profile,originalDone); } - )); + }; + // Give our callback the same arity as the original one from options + if (options.verify) { + Object.defineProperty(verify, "length", { value: options.verify.length }) + } + + passport.use(new strategy.strategy(options, verify)); adminApp.get('/auth/strategy', passport.authenticate(strategy.name, {session:false, failureRedirect: settings.httpAdminRoot }),