2014-10-10 75 views
0

我正在使用expresspassport-linkedin。身份验证流程正常工作,我可以获取用户的基本配置文件,现在我想提出API请求。例如,/v1/people/~/connectionsexpress passport-linkedin,制作api请求

我已经做了一些阅读和试验和错误,但我得到的是Wrong Authentication SchemeInternal Server Error

我有tokentokenSecretverify回调的LinkedInStrategy实例。我如何从这些授权API中获得授权?

+0

req.isAuthenticated()的价值是什么? – xShirase 2014-10-10 00:28:17

+0

'true'。认证起作用。我可以阅读用户的姓名,等等。但我不知道如何使用这些令牌进行授权请求 – slezica 2014-10-10 00:45:49

+0

ok gotcha,请检查我的回答 – xShirase 2014-10-10 00:48:29

回答

1

我使用'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是名您的护照策略中的变量,取决于您设置的方式,它可能会有所不同。基本上,它是你的验证用户的领域之一;-)

+0

如何提出API请求,例如https://api.linkedin.com/v1/people/~/connections '? – slezica 2014-10-10 00:55:58