【问题标题】:How to correctly set up session with everyauth and express?如何正确设置与everyauth 和express 的会话?
【发布时间】:2014-09-11 08:34:19
【问题描述】:

我正在尝试构建一个简单的 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 offacebookis promising: session ; however, the step returns nothing. Fix the step by returning the expected values OR by returning a Promise that promises said values.

我做错了什么?

【问题讨论】:

  • 您是否尝试按照项目页面中的说明启用调试:github.com/bnoguchi/everyauth#debugging---logging-module-steps
  • 此外,队列中至少有一个 facebook 问题和另一个具有 express 4 兼容性的问题...您可能想查看问题队列。 Everyauth 很久没有主动更新了。您可能需要调查 Passport 或其他替代方案。

标签: facebook node.js session express everyauth


【解决方案1】:

已经很晚了,但仍然谈论这个我也为everyauthexpress 4.x而苦恼的事情。

如果您使用的是express 4.x,请通过npm install express-session 安装express-session

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

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

【讨论】:

    猜你喜欢
    • 2016-07-07
    • 2012-05-10
    • 2020-11-08
    • 2015-04-26
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    相关资源
    最近更新 更多