Sto utilizzando la strategia Passport-Linkedin per Passport con Express, per consentire agli utenti di accedere con il proprio profilo LinkedIn.Come impostare l'host corrente per Passport strategy callbackURL?
Ho il codice seguente:
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);
});
}
));
Nella riga 4, devo impostare manualmente l'URL completo di callback. Avevo una stringa per la produzione e una per lo sviluppo, ma i miei URL continuano a cambiare, così come le porte (io uso 2 macchine per svilupparle).
Come si imposta la prima parte dell'URL (http://localhost:3000
) automaticamente? Esiste una proprietà di express
o app
che mi consentirebbe di farlo? Devo ricorrere a un app.use(function(req, res){});
?
Grazie!
Non funziona se l'app non è in esecuzione sul percorso root, ad esempio è in esecuzione su/myapp' invece di '/'. –