[英]express passport-linkedin, making api requests
I'm using express
and passport-linkedin
. 我正在使用
express
和passport-linkedin
。 The authentication flow works fine, I can get the user's basic profile, and now I want to make an API request. 身份验证流程工作正常,我可以获取用户的基本配置文件,现在我要发出API请求。
/v1/people/~/connections
, for example. /v1/people/~/connections
。
I've done some reading and trial and error, but all I get is Wrong Authentication Scheme
or Internal Server Error
. 我已经做了一些阅读和反复试验,但是我得到的只是
Wrong Authentication Scheme
或Internal Server Error
。
I have the token
and tokenSecret
given to the verify
callback of the LinkedInStrategy
instance. 我将
token
和tokenSecret
赋予了LinkedInStrategy
实例的verify
回调。 How do I go from those to an authorized API request? 如何从那些请求转到授权的API请求?
I use a 'isLegit' function running as middleware. 我使用作为中间件运行的“ isLegit”功能。
Example : 范例:
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'});
}
EDIT : 编辑:
To make a request to the linkedIn api, just set up your request with the following options : 要向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
is the name of the variable in your passport strategy, it could be different depending how you've set it up. access_token
是护照策略中变量的名称,根据设置方式的不同,名称可能会有所不同。 basically, it's one of the fields of your authenticated user ;-) 基本上,这是您的已验证用户的字段之一;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.