2014-10-10 78 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