1
votes

I'm having some issues with passport-facebook and nodejs/ express.

Successful logins are handled well. However, for some reason, when a FB connect login fails my application throws a server error which is not caught and returns with status 500. I believe I'm using a fairly standard passport configuration so I'm a bit stuck as to what could be the issue.

In this case, to create an error I'm logging into my sandboxed app with a test user from another app.

The error/ stacktrace indicates the error is in module code I'm not touching:

AuthorizationError at Strategy.OAuth2Strategy.authenticate (/Users/username/Sites/node_projects/applicationname/node_modules/passport-facebook/node_modules/passport-oauth2/lib/strategy.js:126:25) at Strategy.authenticate (/Users/username/Sites/node_projects/applicationname/node_modules/passport-facebook/lib/strategy.js:84:41) at attempt (/Users/username/Sites/node_projects/applicationname/node_modules/passport/lib/passport/middleware/authenticate.js:243:16) at Passport.authenticate (/Users/username/Sites/node_projects/applicationname/node_modules/passport/lib/passport/middleware/authenticate.js:244:7) at callbacks (/Users/username/Sites/node_projects/applicationname/node_modules/express/lib/router/index.js:164:37) at param (/Users/username/Sites/node_projects/applicationname/node_modules/express/lib/router/index.js:138:11) at pass (/Users/username/Sites/node_projects/applicationname/node_modules/express/lib/router/index.js:145:5) at Router._dispatch (/Users/username/Sites/node_projects/applicationname/node_modules/express/lib/router/index.js:173:5) at Object.router (/Users/username/Sites/node_projects/applicationname/node_modules/express/lib/router/index.js:33:10) at next (/Users/username/Sites/node_projects/applicationname/node_modules/express/node_modules/connect/lib/proto.js:193:15)

Here's the route, which is pretty standard:

app.get('/auth/facebook/callback', 
    passport.authenticate('facebook', { successRedirect: '/#',
                                    failureRedirect: '/#login' }));

req.query is

{"error_code":"2102","error_message":"User is not a test user owned by the application"}

After reading about this fixed issue (https://github.com/jaredhanson/passport-oauth/issues/16), I added middleware so that req.query is:

{"error_code":"2102","error_message":"User is not a test user owned by the application","error":true}

Here's the middleware I added (which I'm removing since it didn't work):

app.use(function(req, res, next){
    if (req.query && !req.query.error && req.query.error_code) {
        req.query.error = true;
    }
    next();
});

I should be up to date on my packages & tried uninstalling/ re-installing everything:

"dependencies": {
    "express": "3.x",
    "mongodb": "1.3.x",
    "socket.io": "0.9.x",
    "mongoose": "3.6.x",
    "passport": "0.1.x",
    "passport-facebook": "1.0.x",
    "passport-local": "0.1.x",
    "bcrypt": "0.7.x",
    "handlebars": "1.0.x",
    "consolidate": "0.9.x",
    "imagemagick": "0.1.x",
    "aws-sdk": "1.12.x"
},

No luck so far and running out of ideas, short of hacking the module directly which seems unnecessary.

Any thoughts?

Thanks very much in advance.

1

1 Answers

1
votes

Try changing your application from sandboxed to non-sandboxed, and attempt to recreate the error.