我正在构建一个具有通配符子域的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上应该被拒绝
通常,我会使用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
});
}
));发布于 2018-09-21 15:51:39
我找到了解决方案,所以回答我自己的问题,以防有人需要知道如何在使用passport.js的任何策略中显示req,您所需要做的就是将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
});
}
));https://stackoverflow.com/questions/52434198
复制相似问题