简体   繁体   中英

Linkedin Oauth2 Authentication Invalid Request

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"}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM