2014-10-06 46 views
11

我必須使用護照谷歌-的OAuth以下節點的代碼...護照谷歌,OAuth的回調不工作

app.get('/auth/google', passport.authenticate('google', { scope : ['profile', 'email'] })); 

app.get('/auth/google/callback', function(req,res) { 
    console.log("callback"); 
    passport.authenticate('google', { 
       successRedirect : '/signin', 
       failureRedirect : '/signin' 
    }); 
}); 

和...

passport.serializeUser(function(user, done) { 
    console.log("ser"); 
    done(null, user.id); 
}); 

passport.deserializeUser(function(id, done) { 
    console.log("des"); 
    User.findById(id, function(err, user) { 
     done(err, user); 
    }); 
}); 

passport.use(new GoogleStrategy({ 

    clientID  : 'id', 
    clientSecret : 'key', 
    callbackURL  : 'http://host/auth/google/callback', 
}, 
function(token, rtoken, profile, done) { 
    console.log("proc"); 
    console.log(profile); 
    done(null, profile); 
})); 

的問題是,回調被叫,但沒有其他事情發生。處理功能從未命中。回調結束超時。任何想法,我出錯了?

+0

是行'console.log(「callback」);'執行了嗎? – xShirase 2014-10-06 18:16:45

+0

你還有什麼/登錄路線的樣子?也應該回調是一個get或post。我認爲這通常是一個職位。 – 2014-10-06 22:59:17

+0

也許你的問題出現在GoogleStrategy中。試試這個:var GoogleStrategy = require('passport-google-oauth')。OAuth2Strategy; – Dyrk 2015-05-07 11:04:31

回答

1

我剛剛發現,護照,谷歌,OAuth的包導出以下:

exports.Strategy = 
exports.OAuthStrategy = OAuthStrategy; 
exports.OAuth2Strategy = OAuth2Strategy; 

這意味着,「默認」(即策略)沒有的oauth2在所有...所以你最好明確使用OAuth2Strategy。它爲我工作。花了我幾個小時才發現這是個問題...