我使用'isLegit'函数作为中间件运行。
例子:
app.get('/api/mysecuredpage',isLegit,function(req,res){
res.render('mysecurepage');
});
function isLegit(req, res, next) {
// if user is authenticated in the session, next
if (req.isAuthenticated())
return next();
// if they aren't send an error
res.json({error:'You must be logged in to view information'});
}
编辑:
要对LinkedIn的API的请求,只设置了下列选项您的要求:
var options = {
url: 'https://api.linkedin.com/v1/people/~/connections',
headers: { 'x-li-format': 'json' },
qs: { oauth2_access_token: user.access_token }
};
request(options,function(err,res,body){
console.log(body);
});
access_token
是名您的护照策略中的变量,取决于您设置的方式,它可能会有所不同。基本上,它是你的验证用户的领域之一;-)
req.isAuthenticated()的价值是什么? – xShirase 2014-10-10 00:28:17
'true'。认证起作用。我可以阅读用户的姓名,等等。但我不知道如何使用这些令牌进行授权请求 – slezica 2014-10-10 00:45:49
ok gotcha,请检查我的回答 – xShirase 2014-10-10 00:48:29