bnoguchi / everyauth

node.js auth package (password, facebook, & more) for Connect and Express apps
http://everyauth.com/
3.49k stars 447 forks source link

LinkedIn/OAuth Uncaught Error #32

Closed coreybutler closed 13 years ago

coreybutler commented 13 years ago

I'm not sure if I'm missing something in the implementation, but I'm getting errors using the LinkedIn module.

User's click the link to login and get redirected to the LinkedIn login page as expected. If they grant access to the application, there are no problems. However; if they cancel or reject the application, an error is thrown. Specifically, it complains about line 46 of linkedin.js, which is part of the convertErr method - specifically parsing a JSON response. The problem is there is no JSON response from LinkedIn. The user is sent back to the redirect URL with the oauth_problem=user_refused attribute appended.

Here's the error dump to the Node console:

SyntaxError: Unexpected token ILLEGAL
    at Object.parse (native)
    at /usr/local/lib/node_modules/everyauth/lib/modules/linkedin.js:46:21
    at /usr/local/lib/node_modules/everyauth/lib/step.js:97:21
    at [object Object].fail (/usr/local/lib/node_modules/everyauth/lib/promise.js:52:24)
    at /usr/local/lib/node_modules/everyauth/lib/modules/oauth.js:151:24
    at /usr/local/lib/node_modules/oauth/lib/oauth.js:345:22
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/oauth/lib/oauth.js:312:11)
    at IncomingMessage.emit (events.js:81:20)
    at HTTPParser.onMessageComplete (http.js:133:23)
    at CleartextStream.ondata (http.js:1226:22)

Here's the code I'm using:

var usersByLinkedinId = {};
everyauth.linkedin
  .myHostname('http://' + domain)
  .consumerKey( linkedin.appKey )
  .consumerSecret( linkedin.appSecret )
  .authorizePath('/uas/oauth/authenticate')
  .callbackPath('/auth/linkedin/callback')
  .findOrCreateUser( function (sess, accessToken, accessSecret, linkedinUser) {
    return usersByLinkedinId[linkedinUser.id] || (usersByLinkedinId[linkedinUser.id] = linkedinUser);
  })
  .redirectPath('/');

Furthemore, I originally tried to add a handleAuthCallbackError before I noticed that was only implemented in the OAuth2 module, not OAuth that the LinkedIn module leverages.

So there are two things. One, am I doing something wrong here? It appears there may be bug or I'm simply too sleep derived to see the obvious. Second, it would be nice if there were an error handler in both OAuth modules to maintain consistency.

Thanks for all the work on everyauth!

bnoguchi commented 13 years ago

Close via a recent commit.