[英]express passport-linkedin, making api requests
我正在使用express
和passport-linkedin
。 身份驗證流程工作正常,我可以獲取用戶的基本配置文件,現在我要發出API請求。 /v1/people/~/connections
。
我已經做了一些閱讀和反復試驗,但是我得到的只是Wrong Authentication Scheme
或Internal Server Error
。
我將token
和tokenSecret
賦予了LinkedInStrategy
實例的verify
回調。 如何從那些請求轉到授權的API請求?
我使用作為中間件運行的“ 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
是護照策略中變量的名稱,根據設置方式的不同,名稱可能會有所不同。 基本上,這是您的已驗證用戶的字段之一;-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.