0
votes

I've gone through steps 1 and 2 of linkedin OAuth2 authentication (detailed here https://developer.linkedin.com/docs/oauth2), but I am unable to retrieve an access token in step three. I am using a node.js server with express.js to make an https post request to the https://www.linkedin.com/uas/oauth2/accessToken endpoint with all the parameters listed in the docs. My code for the request is:

    // Request paramaters
    var post_data = querystring.stringify({
      'grant_type' : 'authorization_code',
      'code': auth_code,
      'redirect_uri': 'http://localhost:4200/authenticated',
      'client_id': '**************',
      'client_secret': '****************'
    });

    // Request options object
    var post_options = {
      host: 'www.linkedin.com',
      port: '443',
      path: '/uas/oauth2/accessToken',
      method: 'POST'
    };

    // Setup the request
    var post_req = https.request(post_options, function(res) {
      res.setEncoding('utf8');
      res.on('data', function (chunk) {
          console.log('Response: ' + chunk);
      });
    });

    // Post the data
    post_req.write(post_data);
    post_req.end();

However, upon making the request the server logs the following error response from linkedin:

Response: {"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : client_id","error":"invalid_request"}
1
It's great that you are trying to implement social authentication on your own, most people prefer to use passport, it s authentication middleware for Node.js. Try it out, you can save lot of time.NarendraSoni
@NarendraSoni I am using ember.js for the client and firebase to store all my models—I just need this node server to communicate with the linkedin api for authentication and to pull the user's full profile the first time they authenticate. Can I initialize passport and the passport-linkedin package with a user authorization code from the linkedin auth redirect in step 1 of their docs?mmwebster
i am more into AngularJS, haven't got change to look into EmberJS but i believe the concept must be very much similar. Find my github repo for mean-passport-auth i developed this couple of days back for role based local and Facebook authentication. I think you can get an idea and implement same thing in EmberJS. To add to it. I will be improving this app in a week or so to feature ** javascript web token(JWT) ** based authentication. That will be the best. So try to achieve same. All the best.NarendraSoni
Awesome, I'll look into it.mmwebster

1 Answers

0
votes

Passport.js is a commonly used authentication middleware for Node.js that greatly streamlines and simplifies these authentication requests. It supports 3rd party authentication from over 100 different providers (including linkedin, facebook and twitter) using OAuth and OAuth 2.0 protocols. Each of these parties has its own node package (listed on the site) that can be installed and required in your node app, in addition to passport.js, to begin authenticating with that particular provider. Passport has a number of features including persistent sessions and login success/failure callbacks.