我使用Passport with Express的Passport-Linkedin戰略,允許用戶使用其LinkedIn個人資料登錄。如何設置Passport策略的當前主機策略callbackURL?
我有以下代碼:
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){});
嗎?
謝謝!
如果您的應用程序未在根路徑上運行,則不起作用,例如,它在'/ myapp'而不是'/'上運行。 –