passport-linkedin: InternalOAuthError - failed to obtain request token

I am looking to use passport-linkedin in my application. I have successfully implemented same for twitter, facebook and instagram. However with linkedin, I get getting the following error

InternalOAuthError: failed to obtain request token
    at /Users/davey/code/node/appify-frontend/node_modules/passport-linkedin/node_modules/passport-oauth/lib/passport-oauth/strategies/oauth.js:196:36
    at /Users/davey/code/node/appify-frontend/node_modules/passport-linkedin/lib/passport-linkedin/strategy.js:80:19
    at passBackControl (/Users/davey/code/node/appify-frontend/node_modules/passport-linkedin/node_modules/passport-oauth/node_modules/oauth/lib/oauth.js:397:13)
    at IncomingMessage.<anonymous> (/Users/davey/code/node/appify-frontend/node_modules/passport-linkedin/node_modules/passport-oauth/node_modules/oauth/lib/oauth.js:409:9)
    at IncomingMessage.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)
GET /oauth/linkedin 500 1074ms - 786b

Here’s what my code looks like

xports.setup = function (config) {
  var passport = require('passport');
  var LinkedinStrategy = require('passport-linkedin').Strategy;

  passport.use(new LinkedinStrategy({
      consumerKey: config.linkedin.clientID,
      consumerSecret: config.linkedin.clientSecret,
      callbackURL: config.linkedin.callbackURL
    },
    function(token, tokenSecret, profile, done) {
      console.log(token, tokenSecret, profile);
      return done(null, true);
    }
  ));
};

and here’s the routing setup

router
    .get('/', 
        function(req, res, next) {
            console.log("[OAuth2:redirect:query]:", JSON.stringify(req.query));
            console.log("[OAuth2:redirect:body]:", JSON.stringify(req.body));
            next();
          },
        passport.authenticate('linkedin', {
        failureRedirect: '/settings/connected-accounts',
        session: false
    }))

    .get('/callback', passport.authenticate('linkedin', {
        failureRedirect: '/settings/connected-accounts',
        session: false
    }), function (req, res){
        res.redirect('/settings/connected-accounts');
    });

Also, I have setup the appropriate endpoints on linkedin as follows;

Authorized Redirect URLs:

    http://testdomain.ngrok.io/oauth/linkedin/callback
    http://localhost:9000/oauth/linkedin/callback
    http://127.0.0.1:9000/oauth/linkedin/callback

Default “Accept” Redirect URL:

    http://testdomain.ngrok.io/settings/connected-accounts
    http://localhost:9000/settings/connected-accounts

I tried each of the above but always had the same error. I don’t know what to do next, I’d really appreciate any help. Thanks 😃

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 6
  • Comments: 15

Most upvoted comments

I had this issue and had to use

https://github.com/jaredhanson/passport-google-oauth2

rather than the basic google auth in the docs to make it work. It looks like the original uses an outdated URL.

Well I was getting the same error but then i used
var GoogleStrategy = require(‘passport-google-oauth’).OAuth2Strategy; instead of .OAuthStrategy … It worked for me

yes … I tried everything… Now I am using “passport-linkedin-oauth2” NPM. Its working smoothly for me.

Thank you for your quick reply.

  • Gaurav