node.js - 更改后重新处理请求
问题描述
我正在尝试以passport.js
通用方式使用,在调用之前更改配置authenticate
,但之后我找不到将请求重定向到它的方法。
我处理这样的请求:
入口点:
app.get('/authorize/:clientId/:network', authUtils.authorize);
处理程序:
async function authorize(request, response, next) {
try {
let clientId = request.params.clientId;
let network = request.params.network;
config = await databaseUtils.getConfig(clientId, network);
if(typeof(config) !== 'undefined') {
passport.use(new FacebookStrategy({
clientID: config.appId,
clientSecret: config.appSecretKey,
callbackURL: 'https://127.0.0.1/' + network + '/authCallback/'
}, function(accessToken, refreshToken, profile, cb) {
return {accessToken, refreshToken, profile, cb};
}));
// Here's where I should re-handle request
passport.authenticate(network);
} else {
throw new Error(network + ' is not configured');
}
} catch (e) {
throw e;
}
}
我确定使用passport.authenticate('network')
as request handler 是可行的,但我想让它通用,这样我就可以使用不同的社交网络。
有没有办法在 NodeJS/Express 中“重新处理”请求?
解决方案
由于中间件的所有步骤都应该返回一个带有 3 个参数的函数,也许您可以使用这 3 个参数调用它返回的内容:
return passport.authenticate(network)(request, response, next);
推荐阅读
- c# - 使用 MAPI/contentID 方法将嵌入图像作为附件发送时如何删除已发送邮件中的附件图标
- python - 如何让我的循环 python 脚本运行得更快并使用更少的循环?
- angular - 如何使用angualr向父母公开孩子ID
- java - 为什么 Hystrix 会创建这么多线程?为什么等待线程?
- javascript - 无法在 iOS 模拟器中启动 Nativescript 应用程序
- java - 如何通过接口数组转换抽象类数组
- dataframe - 使用组合的 Julia Dataframes Groupby 链
- android - Google PanoramaAPI 停止在 Android 11 上运行
- node.js - 如何将 HTTP 请求重定向到 Windows 上的 localhost?
- shell - Unix Shell:根据其他列值更新列值