大津です。

環境がわからないので試せてないですが、

>      cookie: {
>
>          httpOnly: false,
>
>          maxAge: new Date(Date.now() + 60 * 60 * 1000)
>
>      }

maxAgeは、expireと違ってクッキー生成後の有効時間(秒)を指定するものです。(RFC6265 5.2.2 参照)

手元の express(3.5.1)で読み込んでる cookie(0.1.1) を見てみると、 maxAge - 0 で toNumber しているので、
1時間後の epoch 時間秒分だけクッキーが有効になっているのが原因じゃないかと想像します。


(2014/03/26 2:19), Leo Azuki wrote:
passport.jsにて認証を実装しています。

認証してログインできるのですが、セッションがきれた後にログイン画面に強制的に戻り、そこで再度ログインしようとすると以下のようなエラーがでてしまい
ます。

csrfの設定が悪さをしているのかなと思ったのですが、最初のログイン時には問題なく動いています。


以下が設定です。

  app.configure(function() {

     app.set('port', process.env.PORT || 3000);

     app.use(logger.log4js.connectLogger(

         logger,

         { level: logger.log4js.levels.INFO,

             nolog: ["\\.css", "\\.js", "\\.jpg", "\\.jpeg", "\\.gif"]

         })

     );

     app.use(express.logger('dev'));

     app.use(express.limit('2mb'));

     app.use(express.bodyParser({

         keepExtensions: true,

         uploadDir: './uploads/fullsize'

     }));

     app.use(express.cookieParser());

     app.use(express.session({

     secret: 'abcde',

     store: new MongoStore({

         db: 'session',

         host: 'localhost',

         clear_interval: 60 * 60 //セッションタイムアウトの時間を1時間に設定

     }),

     cookie: {

         httpOnly: false,

         maxAge: new Date(Date.now() + 60 * 60 * 1000)

     }

     }));

     app.use(express.methodOverride());

     app.use(express.static(path.join(application_root, 'public')));

     app.use(express.favicon(path.join(application_root, 
'public/img/favicon.ico')));

     //passportのinitializeとsessionを使います。

     app.use(passport.initialize());

     app.use(express.csrf());

     app.use(passport.session());

     app.use(flash());

     app.use(express.compress());

     app.use(app.router);

     app.use(lib.notFoundHandler);

     app.use(lib.errorHandler);

  });


function csrf(req, res, next) {

     res.cookie('XSRF-TOKEN', req.session._csrf);

     res.locals.token = req.session._csrf;

     next();

}

以下がそのエラーです。

Forbidden: Forbidden

     at next 
(/Users/test/projects/myProjest/proto/node_modules/express/node_modules/connect/lib/proto.js:125:13)

     at Object.handle 
(/Users/test/projects/myProjest/proto/node_modules/express/node_modules/connect/lib/middleware/csrf.js:54:30)

     at next 
(/Users/test/projects/myProjest/proto/node_modules/express/node_modules/connect/lib/proto.js:199:15)

     at Object.initialize [as handle] 
(/Users/test/projects/myProjest/proto/node_modules/passport/lib/middleware/initialize.js:62:5)

     at next 
(/Users/test/projects/myProjest/proto/node_modules/express/node_modules/connect/lib/proto.js:199:15)

     at Object.favicon [as handle] 
(/Users/test/projects/myProjest/proto/node_modules/express/node_modules/connect/lib/middleware/favicon.js:78:7)

     at next 
(/Users/test/projects/myProjest/proto/node_modules/express/node_modules/connect/lib/proto.js:199:15)

     at Object.static 
(/Users/test/projects/myProjest/proto/node_modules/express/node_modules/connect/lib/middleware/static.js:55:61)

     at next 
(/Users/test/projects/myProjest/proto/node_modules/express/node_modules/connect/lib/proto.js:199:15)

     at Object.methodOverride [as handle]
(/Users/test/projects/myProjest/proto/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:37:5)

--

---
このメールは Google グループのグループ「Node.js 日本ユーザグループ」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには nodejs_jp+unsubscr...@googlegroups.com
<mailto:nodejs_jp+unsubscr...@googlegroups.com> にメールを送信してください。
その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。

--

--- このメールは Google グループのグループ「Node.js 日本ユーザグループ」の登録者に送られています。
このグループから退会し、グループからのメールの配信を停止するには nodejs_jp+unsubscr...@googlegroups.com 
にメールを送信してください。
その他のオプションについては、https://groups.google.com/d/optout にアクセスしてください。

メールによる返信