2016-11-29 70 views
0

我開發了一個node.js應用程序,它有一個谷歌登錄。我開發了谷歌登錄使用。部分用戶無法登錄到我的谷歌應用程序

"passport": "^0.3.2" 
"passport-google-oauth": "^1.0.0" 

我擔心的是,除了少數用戶以外,其他所有人都可以訪問它。

下面是實現

[..] 

module.exports = function (passport, config) { 

    // used to serialize the user for the session 
    passport.serializeUser(function (user, done) { 
     console.log(user.id); 
     done(null, user); 
    }); 

    // used to deserialize the user 
    passport.deserializeUser(function (user, done) { 
     console.log("before derializing"); 
     done(null, user); 
    }); 

    passport.use(
     new GoogleStrategy(
      { 
       clientID: config.googleAuth.clientID, 
       clientSecret: config.googleAuth.clientSecret, 
       callbackURL: config.googleAuth.callbackURL 
      }, 
      function (token, refreshToken, profile, done) { 
       process.nextTick(function() { 
        console.log("user is authenticated" + profile.displayName); 
        //TODO sign up 
        done(null, profile); 
       }); 
      } 
     ) 
    ); 
}; 

欣賞你幫助

+0

您是否有任何異常或其他附加信息? –

回答

0

找到了答案.....

在這個我已經保持了輪廓(輪廓對象來自谷歌)作爲會話對象。而某些配置文件對象包含特殊字符,這些特殊字符會在護照中設置會話時導致錯誤。

因此,爲會話維護一個單獨的對象解決了這個問題,如下所示。

passport.use(
    new GoogleStrategy(
     { 
      clientID: config.googleAuth.clientID, 
      clientSecret: config.googleAuth.clientSecret, 
      callbackURL: config.googleAuth.callbackURL 
     }, 
     function (token, refreshToken, profile, done) { 
      process.nextTick(function() { 
       console.log("user is authenticated" + profile.displayName); 
       //TODO sign up 
       done(null, { 
        displayName: profile.displayName 
       }); 
      }); 
     } 
    ) 
); 
相關問題