node.js - 护照的身份验证功能如何知道要验证哪个请求?
问题描述
护照文档使用它来保护路线:
app.get('/api/me',
passport.authenticate('basic', { session: false }),
function(req, res) {
res.json(req.user);
});
如何authenticate()
知道要验证哪个请求?我没有将请求传递给它。
解决方案
The passport.authenticate
returns a function.
You can try this
console.log(passport.authenticate('basic', { session: false }));
and it will print something like
function(req, res, next){ ... }
This means that the app.get
will look something like this after your app starts
app.get('/api/me',
function(req, res, next){
// now passport has access to the "req" even though you didn't pass request to it
// passport's authentication logic here
},
function(req, res) {
res.json(req.user);
});
推荐阅读
- reactjs - 如何避免 React 中不必要的重新渲染?
- javascript - 有没有办法将按钮连接到功能
- json - 在 JsonServer.io 上生成字符串而不是对象
- php - Laravel 包开发中的会话已过期
- javascript - undefined "获取失败"
- javascript - 单击图标侧边栏后从右侧出现
- laravel - 外键关系和 php artisan 迁移
- python - 无法让 matplotlib 与 eclipse pydev 一起使用
- sql - SQLITE / 查找在 2010 年春季之前没有参加过任何课程的所有学生的 ID 和姓名
- xcode - 断言图像存在于 UITest 中的按钮上