2013-03-05 27 views
2

我正在嘗試使用express/node.js應用程序的護照。出於某種原因,我無法使用Google進行身份驗證。 Google提供以下錯誤:Passport w/node.js谷歌錯誤

錯誤:invalid_request
解析OpenID身份驗證請求時出錯。

Code: 

    passport.serializeUser(function(user, done) { 
    done(null, user.id); 
}); 

passport.deserializeUser(function(user, done) { 
    done(null, user); 
}); 

var GoogleStrategy = require('passport-google').Strategy; 
var UserModel = require('./models/usermodel'); 

passport.use(new GoogleStrategy({ 
    returnURL: 'http://localhost:3000/auth/google/return', 
    realm: 'http:/localhost:3000' 
    }, 
    function(identifier, profile, done) { 
    profile.email = profile.emails[0].value; 
    UserModel.findOneAndUpdate({email:profile.email}, {$set:profile, $inc:{logins:1}}, {upsert:true}, done); 
    } 
)); 
+0

檢查這個答案出來,實現細節使用的oauth2 [鏈接] [1] [1]:HTTP://計算器。 COM /問題/ 24352975 /護照谷歌-OAuth的上本地主機 – 2014-06-22 18:29:33

回答

6

如果你沒有因其他原因使用的OpenID,我強烈建議切換到的OAuth 2.0,這是在passport-google-oauth實現。

谷歌似乎在推薦,作爲他們首選的認證解決方案,他們的OpenID實施似乎沒有受到重視併發生虛假錯誤。

0

我知道這是多麼遲,但我認爲值得注意的是你的領域是不正確的,這可能是你得到這個錯誤的原因。協議後只有一個斜槓 - http:/local而不是https://local

0

第一件事第一。確保你的寶石是最新的。因此,將此添加到您的package.json中,然後運行npm install或npm update。我99%肯定這是因爲一箇舊的谷歌寶石打破了我的。

{ 
    "name": "Boilerplate", 
    "version": "0.0.2", 
    "private": true, 
    "scripts": { 
    "start": "node app" 
    }, 
    "dependencies": { 
    "express": "3.1.0", 
    "ejs": "*", 
    "stylus": "*", 
    "mongoose": "*", 
    "connect-mongo": "*", 
    "passport": "*", 
    "passport-google": "*", 
    "passport-twitter": "*", 
    "passport-facebook": "*", 
    "passport-local": "*" 
    } 
} 

然後運行:

npm install 

以下是我對我的server.js護照信息

passport.serializeUser(function(user, done) { 
    done(null, user.id) 
}) 

passport.deserializeUser(function(id, done) { 
    UserModel.findOne({ _id: id }, function (err, user) { 
    done(err, user) 
    }) 
}) 

var GoogleStrategy = require('passport-google').Strategy; 
var UserModel = require('./models/usermodel'); // A schema that is not optional 

passport.use(new GoogleStrategy({ 
    returnURL: 'http://localhost:3000/auth/google/return', 
    realm: 'http://localhost:3000' 
    }, 
    function(identifier, profile, done) { 
    console.log(profile); 
     UserModel.findOneAndUpdate({email:profile.email}, {$set:profile, $inc:{logins:1}}, {upsert:true}, done); 
    } 
)); 
0

看來RETURNURL不能很好地發揮,當一個端口號包含在其中。 這意味着你可能需要切換到標準端口(80),除非你調整了操作系統以允許非root用戶訪問該端口,否則在某些linux口中將不起作用。我會考慮的OAuth 2.0不過,正如上文所說,前跳水