lundi 30 mars 2015

Linkedin oauth - how to send access_token to request user profile data

I'm trying to access user profile information from the LinkedIn API using Angular, Node.js, and the node-linkedin npm module. I have the first two parts completed (getting the code, and getting the access_token). So, I now have my user authenticated, and I have their access_token, but I can't figure out how to send that token in my HTTP request to pull their profile data.


So my first three routes look like this (they are in a controller and they are all get requests):



linkedInReq: function(req, res){
Linkedin.auth.authorize(res, ['r_basicprofile']);
},
linkedInCallback: function(req, res){
Linkedin.auth.getAccessToken(res, req.query.code, function(err, results){
if(err) throw err;
var user = new User({
linkedin: JSON.parse(results)
});
user.save();
res.redirect('/main');
});
},
getMain: function(req, res){
res.render('main');
},


This is working fine, and 'results' in the linkedInCallback route contains the access token (user.linkedin). Now, I have one last route to request the user profile data that looks like this:



getProfile: function(req, res){
var linkedin = Linkedin.init(access_token_goes_here);
linkedin.people.me(function(err, $in){
res.send($in);
});
}


The problem I'm having is how to get the user's access token so I can pass it to the Linkedin.init method. The getProfile route is being hit by an Angular $resource in a factory connected to my controller. I've tried every possible solution I can think of, but I'm at a loss. This is my first time trying to make an API connection with oauth.


Aucun commentaire:

Enregistrer un commentaire