jaredhanson / passport-linkedin

LinkedIn authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-linkedin/?utm_source=github&utm_medium=referral&utm_campaign=passport-linkedin&utm_content=about
MIT License
141 stars 71 forks source link

InternalOAuthError - failed to obtain request token #19

Open elimence opened 9 years ago

elimence commented 9 years ago

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 :)

jackcohen5 commented 9 years ago

Also having this issue, any luck?

elimence commented 9 years ago

No luck, but recheck your key's, I've had trouble with those in other cases.

jackcohen5 commented 9 years ago

Try running npm update and bower update

After running both of those, I got it working again

elimence commented 9 years ago

Ok, will give that a shot, and thanks :)

gauravbansal74 commented 9 years ago

Hi I am getting same error. Please help me to resolve this.

TIA. Gaurav

jackcohen5 commented 9 years ago

Did you try running npm update and bower update?

gauravbansal74 commented 9 years ago

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

Thank you for your quick reply.

arung-ideas2it commented 8 years ago

Hey guys ! I am using Mean IO where they followed OAuth 1. x strategy for LinkedIn....Could you help to overcome this issue

a455bcd9 commented 8 years ago

@elimence It seems that you used OAuth2, this package is a strategy for authenticating with LinkedIn using the OAuth 1.0a API. Try using https://github.com/auth0/passport-linkedin-oauth2 instead, it should work.

askucher commented 8 years ago

Dame same issue.

MyNameIsAlaa commented 7 years ago

same issue here! any solution?

kmokrzycki commented 7 years ago

Initially I had very same issue and my problem was the scope.I was asking for non-existing scope r_fullprofile that is not available any more, and funny enough this was failing only occasionally not all the time, there must be some inconsistency at LinkedIn side.

Try to limit you scope just to a single known value.

jaredwa commented 7 years ago

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.

umairjyetoo commented 6 years ago

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

shibly97 commented 3 years ago

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

this worked for me as well