passport.js 还需要使用 cookie-parser 吗?
Usage of cookie-parser with passport.js still needed?
无法在 passport.js
站点上找到任何关于 passport.js
在 node.js
中的一般安装和声明的信息。
在教程中,我总是看到 express session
中间件和 cookie-parser
声明为 passport
,但 session
文档 (https://github.com/expressjs/session) 注释:
'Since version 1.5.0, the cookie-parser middleware no longer needs to be used for this module to work. This module now directly reads and writes cookies on req/res. Using cookie-parser may result in issues if the secret is not the same between this module and cookie-parser.'
那么出于某些原因,我是否需要为 passport
使用 session
和 cookie-parser
,或者我只能使用 session
,我是否需要调整一些东西?
不,passport 本身不需要 cookie-parser 中间件。如果您想要会话持久身份验证,那么您将需要 express-session 中间件,使用 来要求 cookie-parser,但现代版本的 express 不再有此要求(当前版本express-session 直接读取和写入 cookie)。
无法在 passport.js
站点上找到任何关于 passport.js
在 node.js
中的一般安装和声明的信息。
在教程中,我总是看到 express session
中间件和 cookie-parser
声明为 passport
,但 session
文档 (https://github.com/expressjs/session) 注释:
'Since version 1.5.0, the cookie-parser middleware no longer needs to be used for this module to work. This module now directly reads and writes cookies on req/res. Using cookie-parser may result in issues if the secret is not the same between this module and cookie-parser.'
那么出于某些原因,我是否需要为 passport
使用 session
和 cookie-parser
,或者我只能使用 session
,我是否需要调整一些东西?
不,passport 本身不需要 cookie-parser 中间件。如果您想要会话持久身份验证,那么您将需要 express-session 中间件,使用 来要求 cookie-parser,但现代版本的 express 不再有此要求(当前版本express-session 直接读取和写入 cookie)。