在Passport策略回调中获取请求对象

在Passport策略回调中获取请求对象,第1张

在Passport策略回调中获取请求对象

因此,我通常在有请求时设置策略,而不是在应用程序启动时设置策略。例如:

app.get(    '/facebook/login'    ,passport_setup_strategy()    ,passport.authenticate()    ,redirect_home());var isStrategySetup = false;var passport_setup_strategy = function(){    return function(req, res, next){        if(!isStrategySetup){ passport.use(new FacebookStrategy({         clientID: ".....",         clientSecret: ".....",         callbackURL: "http://localhost:1337/register/facebook/callback",     },     function (accessToken, refreshToken, profile, done) {          process.nextTick(function () {      // here you can access 'req'  .......         });         } )); isStrategySetup = true;        }        next();    };}

使用此方法,您可以访问验证处理程序中的请求。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5172580.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-18
下一篇2022-11-18

发表评论

登录后才能评论

评论列表(0条)

    保存