我有一个多租户应用程序,每个租户可以有不同的策略。我想在中间件或路由处理程序中设置通行证策略。
这是我想做的示例代码:
function loadTenantProviderSettings(req){
// return settings
}
function generateProviderStrategy(provider, settings){
// return strategy instance. ex:
// new GoogleStrategy({ ...settings },
// (accessToken, refreshToken, profile, done) => {
// return done(null , profile);
// },
// ))
}
app.get('/socialLogin/:provider', function(req,res,next){
const socialProvider = req.params.provider
const settings = loadTenantProviderSettings(req);
// Following works but I don't find it right. Because passport is singleton
// passport.use( generateProviderStrategy(socialProvider, settings ) )
// passport.authenticate(socialProvider, async (err, user, info ) => { })(req,res,next)
passport.authenticate(socialProvider, settings, async (err, user,info) => { })(req,res,next)
})
预先感谢