jwk*_*koo 14 javascript node.js npm node-modules passport.js
我现在正试图在我的应用程序中应用护照模块.
我正在读一些手册,据说,
app.use(passport.initialize());
app.use(passport.session());
Run Code Online (Sandbox Code Playgroud)
什么是app.use(passport.initialize())究竟在做什么?
passport.session() 可能是护照使用会话信息,
但我不知道 passport.initialize()
jpe*_*nna 18
有时最好查看代码:initialize() 上的passport github
TL; 博士
使用会话,initialize()设置函数以序列化/反序列化请求中的用户数据。
你不需要使用passport.initialize(),如果你不使用sessions。
/**
* Passport initialization.
*
* Intializes Passport for incoming requests, allowing authentication strategies
* to be applied.
*
* If sessions are being utilized, applications must set up Passport with
* functions to serialize a user into and out of a session. For example, a
* common pattern is to serialize just the user ID into the session (due to the
* fact that it is desirable to store the minimum amount of data in a session).
* When a subsequent request arrives for the session, the full User object can
* be loaded from the database by ID.
*
* Note that additional middleware is required to persist login state, so we
* must use the `connect.session()` middleware _before_ `passport.initialize()`.
*
* If sessions are being used, this middleware must be in use by the
* Connect/Express application for Passport to operate. If the application is
* entirely stateless (not using sessions), this middleware is not necessary,
* but its use will not have any adverse impact.
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8875 次 |
| 最近记录: |