Tra*_*Guy 5 javascript node.js express passport.js
我使用Passport-Linkedin策略为Passport with Express,允许用户使用他们的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);
});
}
));
Run Code Online (Sandbox Code Playgroud)
在第4行,我必须手动设置完整的回调URL.我有一个用于生产的字符串和一个用于开发的字符串,但我的URL不断变化,端口也是如此(我使用2台机器进行开发).
如何http://localhost:3000自动设置URL()的第一部分?有没有的属性express或app将允许我这样做?我需要求助app.use(function(req, res){});吗?
谢谢!
旧问题,可能回答仅适用于较新版本.但是,如果有人遇到这个问题,就像我一样,解决办法就是不在以下内容中指定主机名callbackURL:
passport.use(new LinkedInStrategy({
consumerKey: config.linkedin.LINKEDIN_API_KEY,
consumerSecret: config.linkedin.LINKEDIN_SECRET_KEY,
callbackURL: "/auth/linkedin/callback"
},
Run Code Online (Sandbox Code Playgroud)
为了使其能够用于heroku https重定向,我们必须x-forwarded-protocol通过信任代理来告诉系统信任标头:
passport.use(new LinkedInStrategy({
consumerKey: config.linkedin.LINKEDIN_API_KEY,
consumerSecret: config.linkedin.LINKEDIN_SECRET_KEY,
callbackURL: "/auth/linkedin/callback",
proxy: true
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2293 次 |
| 最近记录: |