我使用passport.js为web日志编写身份验证功能,发现了一个名为代理(proxy)的选项。我搜索了一下,但是没有找到好的答案,也不知道这个选项的作用。有人能为我解释一下吗?谢谢。
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const user=require("./../models/users")
// const mongoose = require('mongoose');
// const keys = require('./keys');
// Load user model
//const User = mongoose.model('users');
module.exports = function(passport){
passport.use(
new GoogleStrategy({
clientID:'===================================================',
clientSecret:'=================================================',
callbackURL:'/auth/google/callback',
proxy: true
}, (accessToken, refreshToken, profile, done) => {
// console.log(accessToken);
// console.log(profile);
const image = profile.photos[0].value.substring(0, profile.photos[0].value.indexOf('?'));
const newUser = {
googleID: profile.id,
firstName: profile.name.givenName,
lastName: profile.name.familyName,
email: profile.emails[0].value,
image: image
}
// Check for existing user
User.findOne({
googleID: profile.id
}).then(user => {
if(user){
// Return user
done(null, user);
} else {
// Create user
new User(newUser)
.save()
.then(user => done(null, user));
}
})
})
);
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser((id, done) => {
User.findById(id).then(user => done(null, user));
});
}