我正在构建带有通配符子域的node.js应用程序。每个子域都将是应用程序的单独部分,该应用程序将基于子域为用户提供单独的身份验证。
例如,假设我的应用将具有 abc.domain.com 和 xyz.domain.com 以及以下用户
User1@gmail.com signs up for abc.domain.com
User2@yahoo.com signs up for xyz.domain.com
User3@msn.com signs up for both abc.domain.com and xyz.domain.com
每个用户只能访问他们注册的子域。因此, User1@gmail.com 应该能够登录 abc.domain.com ,但应该在 xyz.domain.com < / p>
通常,我会使用req.get('host')获取子域,然后从那里提取子域,但据我所知,passport.js没有req参数。无论如何,我是否可以获得用户正在尝试登录的当前站点的子域名?以下是从https://github.com/drudge/passport-facebook-token
复制的通行证-facebook-令牌代码var FacebookTokenStrategy = require('passport-facebook-token');
passport.use(new FacebookTokenStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET
}, function(accessToken, refreshToken, profile, done) {
// SQL statement will go here that will check whether a user is signed up for the subdomain they are logging into. It will also check if the user exists in the database
});
}
));
答案 0 :(得分:-1)
我找到了解决方案,所以回答我自己的问题,以防万一有人需要知道如何使用passport.js在任何策略中显示要求,需要做的就是将passReqToCallBack设置为true。
下面是更新的代码
passport.use(new FacebookTokenStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
passReqToCallback: true // Added for req to show in callback
}, function(req, accessToken, refreshToken, profile, done) {
// SQL statement will go here that will check whether a user is signed up for the subdomain they are logging into. It will also check if the user exists in the database
});
}
));