如何正确设置与Everyauth的会话并表达?

时间:2014-07-20 21:05:24

标签: facebook node.js session express everyauth

我正在尝试构建一个简单的nodejs应用程序,可以使用express和everyauth登录facebook。在README教程here之后,我在app.js中执行了以下设置:

var everyauth = require('everyauth');

everyauth.facebook
    .appId('829428097067274')
    .appSecret('2c4d4a96514aa8374fbc54d611945148')
    .findOrCreateUser(function (session, accessToken, accessTokExtra, fbUserMetadata) {
        // I will fill this in with something real later, but for now
        // I just want something that works with a fake session

        console.log("in find or create user")

        // this is always undefined...
        console.log(session);

        // these look good; I'm getting real user info
        console.log(accessToken);
        console.log(accessTokExtra);
        console.log(fbUserMetadata);

        // I'm not sure what I need to return here. I've tried
        // variations of this.Promise()/promise.fulfill() as well
        return { id: 100, session: "the session" };
    })
    .redirectPath('/');

// ...

// this gives an error saying that session is no longer
// bundled with express, but I'm not sure which package to replace
// it with:
// app.use(express.session());

app.use(everyauth.middleware(app));

当我启动我的应用程序时,我访问localhost:3000 / auth / facebook,它正确地重定向到facebook。我在那里授权应用程序,它将我重定向到localhost:3000 / auth / facebook / callback。但是,这里我的应用程序记录错误:

Step getSession of {Facebook的{1}}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

已经很晚了,但仍然在谈论这个问题,我也在努力与everyauthexpress 4.x进行斗争。

如果您使用express 4.x,请按express-session

安装npm install express-session

使用以下代码,其他一些代码与everyauth的示例相同。

var session = require('express-session');
...
var app = express();
app.use(session({secret : "anything you want"}));
app.use(everyauth.middleware());