404 error for callback Passport Sequelize

620 Views Asked by At

I'm basing a login system on Scotch-IO's tutorial.

I've converted it to use Sequelize instead of Mongoose and now the callback GET requests are giving me a 404 error. The tokens are returned correctly, and the database is updated, however the browser sees a 404.

I thought this was maybe something to do with returning inside the then() promise?

This is an authorization strategy, not authentication. The sessions already contains the user object.

passport.use(new FacebookStrategy({

    clientID        : configAuth.facebookAuth.clientID,
    clientSecret    : configAuth.facebookAuth.clientSecret,
    callbackURL     : configAuth.facebookAuth.callbackURL,
    passReqToCallback : true

},
function(req, token, refreshToken, profile, done) {

    process.nextTick(function() {
        var user            = req.user;
        user.facebook_id    = profile.id;
        user.facebook_token = token;
        user.save().then(function() {
            return done(null, user)
        })
    })

}))

Log:

GET /connect/facebook 302 8ms - 478b
Executing (default): SELECT `id`, `local_email`, `local_password`, `facebook_id`, `facebook_token`, `facebook_email`, `facebook_name`, `twitter_id`, `twitter_token`, `twitter_displayName`, `twitter_username`, `google_id`, `google_token`, `google_email`, `google_name`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`id` = 1 LIMIT 1;
Executing (default): UPDATE `Users` SET `facebook_token`='CAAGHyJfSyzcBAMu7nJxbQQXVbNxHNMUjRvGUkpbz12JjYm9x7daKherDWGgrAFiPStFsbBtwPDBDvcnxY0mFEJipqzRtRL9VTZAUildByZCyWzwrKNDWabZBJAHJvY3Xrs2YB06YPkjkbs8juOlJtLgyRZA8UjO3WfFyEtcA5XFmVB0G5gbPsh32Fl5E0WUOidOpJiCdr1fGLnWXG551',`updatedAt`='2015-06-17 11:36:08.383 +00:00' WHERE `id` = 1
GET /connect/facebook/callback?code=AQD7jEuKTIIXNzLRzgMxmsH4xmNl5vBA_pErNDi0kRPCK0Jaa0iPidQBSe4Zy_c_pPxknkVWKPfqB9JetfFJwUD6-URqlCvJkGLkLUahj8xaXZEfPONGNQ8sjUzC-xftCWqyujrD_ELROwRSLF7YKl0cMvVARwjx-8bHOt7mvIDlBUts3nWFHlTwlOa2qJ1V2NgFyo7z_-nDlcwXIpdIydDKMWvtpQaY1-oLPUXQhs5eGjQRUIC5OUzQZnrIMLfs4X9e8IDx4MxHR0H_CoAwyk9ce0gChOOkccO3NcjIovNdePaLIdtOKIeHxFy6ZfxKzKDD7mROtc-hCY-lCOAljpW7 404 773ms
1

There are 1 best solutions below

0
On BEST ANSWER

I was using passport.authorize but not grabbing the token from req.account rather than req.user as explained at http://passportjs.org/docs/authorize

I'm actually unable to get authorization working, and have reverted to calling authenticate, despite the fact the user is already logged in. This is working fine.