【发布时间】:2025-12-09 01:35:01
【问题描述】:
我在 Passport with Express 中使用 Passport-Linkedin 策略,以允许用户使用他们的 LinkedIn 个人资料登录。
我有以下代码:
passport.use(new LinkedInStrategy({
consumerKey: config.linkedin.LINKEDIN_API_KEY,
consumerSecret: config.linkedin.LINKEDIN_SECRET_KEY,
callbackURL: "http://localhost:3000/auth/linkedin/callback"
},
function(token, tokenSecret, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
// To keep the example simple, the user's LinkedIn profile is returned to
// represent the logged-in user. In a typical application, you would want
// to associate the LinkedIn account with a user record in your database,
// and return that user instead.
return done(null, profile);
});
}
));
在第 4 行,我必须手动设置完整的回调 URL。我有一个用于生产的字符串,一个用于开发的字符串,但是我的 URL 不断变化,端口也是如此(我使用 2 台机器进行开发)。
如何自动设置 URL 的第一部分 (http://localhost:3000)? express 或 app 的属性是否允许我这样做?我需要求助于app.use(function(req, res){});吗?
谢谢!
【问题讨论】:
标签: javascript node.js express passport.js