node.js - express passport-linkedin, making api requests -
i'm using express
, passport-linkedin
. authentication flow works fine, can user's basic profile, , want create api request. /v1/people/~/connections
, example.
i've done reading , trial , error, wrong authentication scheme
or internal server error
.
i have token
, tokensecret
given verify
callback of linkedinstrategy
instance. how go authorized api request?
i utilize 'islegit' function running middleware.
example :
app.get('/api/mysecuredpage',islegit,function(req,res){ res.render('mysecurepage'); }); function islegit(req, res, next) { // if user authenticated in session, next if (req.isauthenticated()) homecoming next(); // if aren't send error res.json({error:'you must logged in view information'}); }
edit :
to create request linkedin api, set request next options :
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
name of variable in passport strategy, different depending how you've set up. basically, it's 1 of fields of authenticated user ;-)
node.js linkedin passport.js
No comments:
Post a Comment