gpt4 book ai didi

javascript - 如何动态配置 Passportjs 策略?

转载 作者:行者123 更新时间:2023-12-01 16:05:01 26 4
gpt4 key购买 nike

我正在玩弄 Passport ,并以这种方式配置我的 Twitter 登录:

passport.use(new TwitterStrategy({
consumerKey: '*****',
consumerSecret: '*****',
callbackURL: "http://blabla/callback"
},
function(token, tokenSecret, profile, done) {
done(null, profile)
}
));
我希望能够根据登录的用户在运行时配置此值: (consumerKey, consumerSecret, callbackURL)。也就是说,每个用户都将拥有他们需要在 Twitter 上注册的 Twitter 应用程序。
有什么建议吗?

最佳答案

而不是提前使用 passport.use() 注册策略,策略可以直接传给authenticate() (而不是传递策略名称)。
例如:

function login(req, res, next) {
var user = req.user;
var consumerKey = getConsumerKeyForUser(user);
// Create a strategy instance specifically for this user.
var strategy = new TwitterStrategy({ consumerKey: consumerKey }, ...);
// Authenticate using the user-specific strategy
passport.authenticate(strategy)(req, res, next);
}
更多关于这项技术的信息可以在这里找到: https://medium.com/passportjs/authenticate-using-strategy-instances-49e58d96ec8c

关于javascript - 如何动态配置 Passportjs 策略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43072392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com