通过 passport jwt 进行身份验证并将对象名称附加到 req 对象 'user'
Authentication by passport jwt and appending the req object with an object name 'user'
当使用 passport-jwt 进行身份验证时,它是否总是在 req 对象后附加一个名为 "user" 的对象?这个名字"user"从哪里来的?
app.post('/profile',
passport.authenticate('jwt', { session: false }),
function(req, res) {
res.send(req.user.profile);
}
);
此代码是否总是将名为 "user"
的对象附加到 req
对象?
这个名字"user"
是从哪里来的?
这是passport source code line 12中passport.authenticate
的定义。所以基本上,passport.authenticate
是一个中间件,它将进行数据提取,然后将数据绑定到 req.user
。
* Applies the `name`ed strategy (or strategies) to the incoming request, in
* order to authenticate the request. If authentication is successful, the user
* will be logged in and populated at `req.user` and a session will be
* established by default. If authentication fails, an unauthorized response
当使用 passport-jwt 进行身份验证时,它是否总是在 req 对象后附加一个名为 "user" 的对象?这个名字"user"从哪里来的?
app.post('/profile',
passport.authenticate('jwt', { session: false }),
function(req, res) {
res.send(req.user.profile);
}
);
此代码是否总是将名为 "user"
的对象附加到 req
对象?
这个名字"user"
是从哪里来的?
这是passport source code line 12中passport.authenticate
的定义。所以基本上,passport.authenticate
是一个中间件,它将进行数据提取,然后将数据绑定到 req.user
。
* Applies the `name`ed strategy (or strategies) to the incoming request, in
* order to authenticate the request. If authentication is successful, the user
* will be logged in and populated at `req.user` and a session will be
* established by default. If authentication fails, an unauthorized response