2016-11-29 71 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 
       }); 
      }); 
     } 
    ) 
); 
相关问题