我想用谷歌按鈕使用護照模塊的節點js登錄。我試圖讓人員電子郵件ID,姓名,個人資料圖片。我正試圖將圖片下載到本地服務器。即使將「電子郵件」添加到範圍內,Google也沒有返回電子郵件ID,也沒有返回的個人資料照片鏈接正在工作。我已經查看了這個問題的各種答案,但都說包含userinfo.email。it現在已被棄用。按照谷歌文檔的新範圍參數是電子郵件 下面是我的代碼 任何幫助表示讚賞 護照谷歌oauth沒有返回電子郵件護照認證
passport.use(new GoogleStrategy({
clientID : configAuth.googleAuth.clientID,
clientSecret : configAuth.googleAuth.clientSecret,
callbackURL : configAuth.googleAuth.callbackURL,
},
function(token, refreshToken, profile, done) {
// make the code asynchronous
// User.findOne won't fire until we have all our data back from Google
process.nextTick(function() {
// try to find the user based on their google id
User.findOne({ 'google.id' : profile.id }, function(err, user) {
if (err)
return done(err);
if (user) {
// if a user is found, log them in
return done(null, user);
} else {
// if the user isnt in our database, create a new user
var newUser = new User();
console.log(profile);
//JSON.parse(profile);
// set all of the relevant information
newUser.google.id = profile.id;
newUser.google.token = profile.token;
newUser.google.name = profile.displayName;
newUser.google.uname = profile.emails[0].value; // pull the first email
newUser.google.dp = profile._json.picture;
console.log('url is');
console.log(newUser.google.name);
console.log(newUser.google.dp);
//console.log(profile.picture);
Download(newUser.google.uname, newUser.google.dp,function(err){
if(err)
console.log('error in dp');
else
console.log('Profile Picture downloaded');
});
// save the user
newUser.save(function(err) {
if (err)
throw err;
return done(null, newUser);
});
}
});
});
}));
};
routes.js
app.get('/connect/google', passport.authorize('google', { scope : ['profile', 'email'] }));
// the callback after google has authorized the user
app.get('/connect/google/callback',
passport.authorize('google', {
successRedirect : '/profile',
failureRedirect : '/'
}));
download.js
module.exports = function(username, uri, callback){
var destination;
request(uri).pipe(fs.createWriteStream("./downloads/"+username+".png"))
.on('close', function(){
console.log("saving process is done!");
});
謝謝。我得到了我的工作:) 你能幫我在FB OAUTH也。我已經得到它的工作,但得到令牌化錯誤。這裏是鏈接http://stackoverflow.com/questions/38299165/how-to-use-random-guid-with-passport-module-and-express-server –
你有沒有獲得授權屏幕每次API嘗試訪問用戶配置文件? –
事實是,我從這開始。我必須做更多的測試,但現在沒有這個問題。 用Facebook登錄我還沒有實現。當我研究這個問題時,如果可以的話,我會盡力幫助你解決你的問題。 – pariasdev