首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >某些用户无法登录我的google应用程序

某些用户无法登录我的google应用程序
EN

Stack Overflow用户
提问于 2016-11-29 17:45:46
回答 1查看 31关注 0票数 0

我已经开发了一个node.js应用程序,其中有一个谷歌登录。我用来开发google登录。

代码语言:javascript
复制
"passport": "^0.3.2"
"passport-google-oauth": "^1.0.0"

我担心的是,除了少数用户,所有其他用户都可以访问它。

下面是实现

代码语言:javascript
复制
[..]

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);
                });
            }
        )
    );
};

感谢您的帮助

EN

回答 1

Stack Overflow用户

发布于 2016-12-11 17:46:59

找到答案了.

在这里,我维护了配置文件(配置文件对象来自google)作为会话对象。并且一些配置文件对象包含在passport中设置会话时会导致错误的特殊字符。

因此,为会话维护一个单独的对象解决了这个问题,如下所示。

代码语言:javascript
复制
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
                });
            });
        }
    )
);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40862535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档