我不知道这是可能的,但我想,以使用不同的设置取决于链接/用户范围的使用多个谷歌的策略。护照的NodeJS - 使用多个谷歌战略
我创建了两个独立的护照变量:
passport = require('passport')
passport2 = require('passport')
我已经安装他们两个如下:
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/callback"
},
function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function(){
// Changing this to return the accessToken instead of the profile information
console.log(profile.displayName);
return done(null, [{token:accessToken,rToken:refreshToken,'profile':profile}]);
});
}
));
passport2.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://localhost:3000/join/callback"
},
function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function(){
// Changing this to return the accessToken instead of the profile information
//console.log(profile);
return done(null, [{token:accessToken,rToken:refreshToken,'profile':profile}]);
});
}
))
对于我的路我有这样的:
app.get('/auth',
passport.authenticate('google', {scope: ['scopes'],
accessType:'offline', approvalPrompt:'force'})
);
app.get('/joinreq',
passport2.authenticate('google', {scope: ['different_scopes]})
);
和我回调是这样的:
app.get('/join/callback', function(req,res){
console.log('made it to the join callback');
res.redirect('/great')
}
app.get('/auth/callback', function(req,res){
console.log('made it to the auth callback');
res.redirect('/index')
}
我能够成功验证每个范围成功 - 我遇到的问题是,我的回调只是去/join/callback
。 好像变passport2
被覆盖的passport
值。
有没有什么办法可以解决这个问题?我想为管理员用户提供一组范围,并为其他人提供一组范围。
作为一个方面说明。 'require'只被调用一次。随后的调用返回初始require调用的缓存版本。 – Maroshii 2014-11-06 21:54:19