0
我使用快递3.x和连接 - 蒙戈和请求模块复制的NodeJS cookie进行内部应用程序的请求
我的应用程序有一些中间件,确保外部请求有一个的access_token。 检查access_token并将一些数据存储在会话中。 然后,我想在应用程序内部调用一个URL,但内部调用获得新会话(因为它是来自用户浏览器请求的单独请求)。 我想要做的是以某种方式将Express签名的Cookie复制到内部请求()中,以便中间件根据原始外部会话标识执行操作。 我曾尝试将Cookie jar传递给请求对象,但它似乎并不支持已签名的cookie。任何想法我可以做到这一点?
/* Middleware to check access tokens */
app.all("/*", requireAuth, function(req, res, next) {
next();
});
function requireAuth(req,res,next) {
if (req.query.access_token && !req.session) {
// Check the access token and popualte stuff in the session
req.session.somedata = 'test';
// Then call a url internall to do something
// My issue is that this INTERNAL request below gets a new session Id
// so it itself returns Not Authorised as its hits the same code
request({
url: 'someurlinside-this-node-app',
method: "GET"
}, function _callback(err, serviceres, body) {
next();
});
}else{
res.send('Not Authorised');
}
}