Everyauth错误

时间:2016-03-09 16:53:25

标签: node.js api express everyauth

我正在尝试在我的nodejs应用程序中使用everyauth,但是在尝试通过Google进行身份验证时,我一直收到以下错误:

Error: Step getSession of `google` is promising: session ; however, the step returns nothing. Fix the step by returning the expected values OR by returning a Promise that promises said values.
    at Step.exec (/home/an/counter/www/node_modules/everyauth/lib/step.js:79:7)
    at /home/an/counter/www/node_modules/everyauth/lib/stepSequence.js:26:34
    at Promise.fulfill (/home/an/counter/www/node_modules/everyauth/lib/promise.js:44:21)
    at /home/an/counter/www/node_modules/everyauth/lib/stepSequence.js:29:19
    at Promise.fulfill (/home/an/counter/www/node_modules/everyauth/lib/promise.js:44:21)
    at Request._callback (/home/an/counter/www/node_modules/everyauth/lib/modules/google.js:91:15)
    at Request.self.callback (/home/an/counter/www/node_modules/everyauth/node_modules/request/request.js:199:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (/home/an/counter/www/node_modules/everyauth/node_modules/request/request.js:1036:10)
    at Request.EventEmitter.emit (events.js:117:20)
TypeError: Cannot read property 'auth' of undefined
    at EveryModule.module.exports.everyModule.submodule.definit.configurable.get.step.accepts.promises.step.accepts.promises.get.step.description.accepts.promises.canBreakTo.step.accepts.promises.step.accepts.promises.step.accepts.promises.step.accepts.promises.step.accepts.promises.step.accepts.promises.step.accepts.promises.stepseq.step.accepts.promises.getAuthUri.requestAuthUri.getCode.getAccessToken.compile.getSession.addToSession.sendResponse.req (/home/an/counter/www/node_modules/everyauth/lib/modules/oauth2.js:234:21)
    at EveryModule._module._super (/home/an/counter/www/node_modules/everyauth/lib/step.js:58:18)
    at EveryModule._addToSession (/home/an/counter/www/node_modules/everyauth/lib/modules/google.js:34:10)
    at Step.exec (/home/an/counter/www/node_modules/everyauth/lib/step.js:60:17)
    at /home/an/counter/www/node_modules/everyauth/lib/stepSequence.js:26:34
    at Promise.fulfill (/home/an/counter/www/node_modules/everyauth/lib/promise.js:44:21)
    at /home/an/counter/www/node_modules/everyauth/lib/stepSequence.js:29:19
    at Promise.callback (/home/an/counter/www/node_modules/everyauth/lib/promise.js:12:8)
    at /home/an/counter/www/node_modules/everyauth/lib/stepSequence.js:28:19
    at Promise.fulfill (/home/an/counter/www/node_modules/everyauth/lib/promise.js:44:21)

http.js:691
    throw new Error('Can\'t set headers after they are sent.');
          ^
Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (http.js:691:11)
    at ServerResponse.res.setHeader (/home/an/counter/www/node_modules/everyauth/node_modules/connect/lib/patch.js:134:22)
    at /home/an/counter/www/node_modules/errorhandler/index.js:139:15
    at fs.js:268:14
    at Object.oncomplete (fs.js:107:15)

以下是源代码:

var secret = '..........';
var express = require('express')
        , methodOverride = require('method-override')
        , bodyParser = require('body-parser')
        , http = require('http')
        , fs = require('fs')
        , routes = require('./routes')
        , db = require('./lib/db')
        , user = require('./lib/user')
        , my = require('./lib/my')
        , conf = require('./lib/conf')
        , storage = require('./lib/storage')
        , everyauth = require('everyauth')
        , errorHandler = require('errorhandler')
        , cookieParser = require('cookie-parser')
        , session = require('express-session')
        , RedisStore = require('connect-redis')(session)
        , redis = require('redis')
        , morgan = require('morgan')
        , heapdump = require('heapdump')
;

global.cookieParser = cookieParser(secret);

global.redisClient = redis.createClient('/var/run/redis/redis.sock');
global.store = new RedisStore({client: global.redisClient});
global.session = session({
        key: 'sid',
        secret: secret,
        store: global.store,
        resave: true,
        saveUninitialized: false,
        //cookie: { secure: true }
});

everyauth.everymodule.findUserById( function (id, callback) { callback(null, global.users.usersById[id]); });
everyauth.google
        .appId(conf.google.clientId)
        .authQueryParam({ access_type:'online', approval_prompt:'auto' })
        .appSecret(conf.google.clientSecret)
        .scope('openid profile email')
        .findOrCreateUser(user.findOrCreateUser)
        .redirectPath('/');
global.everyauth = everyauth;

var app = express();
var accessLogStream = fs.createWriteStream(__dirname + '/var/log/access.log', {flags: 'a'});
app.use(morgan(':remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] - :response-time ms', {stream: accessLogStream }));
app.use(express.static(__dirname + '/static'));
//app.use(express.favicon());
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(global.cookieParser);
app.use(global.session);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(everyauth.middleware());

这是我的user.js:

exports.findOrCreateUser = function (sess, accessToken, extra, googleUser) {
        googleUser.refreshToken = extra.refresh_token;
        googleUser.expiresIn = extra.expires_in;

        var promise = this.Promise();
        var user = exports.findUserByGoogleId(googleUser.id) || exports.newUser('google', googleUser);
        promise.fulfill(user);
        return promise;

}

exports.findUserByGoogleId = function(googleId) {
        for (var userID in global.users.usersById) if (googleId==global.users.usersById[userID].google.id) return global.users.usersById[userID];
        return false;
}

我使用快递4.我已经尝试了使用谷歌找到的所有建议。 npm install express-session和npm update没有帮助。

1 个答案:

答案 0 :(得分:-1)

解决方案就像chmod 777 /var/run/redis/redis.sock一样简单 (或将用户添加到redis组)