Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Google authentication callback never triggers #25

Closed
Mylab6 opened this issue Oct 7, 2014 · 4 comments
Closed

Google authentication callback never triggers #25

Mylab6 opened this issue Oct 7, 2014 · 4 comments

Comments

@Mylab6
Copy link

Mylab6 commented Oct 7, 2014

I'm calling this in my UserController , while the great Google login screen appears , and I can sign in , I never get my log statement .

google: function(req, res) {
passport.authenticate('google', { failureRedirect: '/login', scope: ['email'] }, function(err, user) {

    sails.log(user) ; 
  req.logIn(user, function(err) {
    if (err) {
      console.log(err);
      res.view('500');
      return;
    }

    res.redirect('/');
    return;
  });
})(req, res);

},

Here's a copy of my express.js file with my keys taken out , I'm trying to run a basic log statement here too...

var passport = require('passport')

,  GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;

var verifyHandler = function(token, tokenSecret, profile, done) {
sails.log("p" ) ;
process.nextTick(function() {

User.findOne({uid: profile.id}, function(err, user) {
  if (user) {
    return done(null, user);
  } else {

    var data = {
      provider: profile.provider,
      uid: profile.id,
      name: profile.displayName
    };

    if (profile.emails && profile.emails[0] && profile.emails[0].value) {
      data.email = profile.emails[0].value;
    }
    if (profile.name && profile.name.givenName) {
      data.firstname = profile.name.givenName;
    }
    if (profile.name && profile.name.familyName) {
      data.lastname = profile.name.familyName;
    }

    User.create(data, function(err, user) {
      return done(err, user);
    });
  }
});

});
};

passport.serializeUser(function(user, done) {
done(null, user.uid);
});

passport.deserializeUser(function(uid, done) {
User.findOne({uid: uid}, function(err, user) {
done(err, user);
});
});

/**

  • Configure advanced options for the Express server inside of Sails.
    *

  • For more information on configuration, check out:

  • http://sailsjs.org/#documentation
    */
    module.exports.http = {

    customMiddleware: function(app) {

    passport.use(new GoogleStrategy({
    clientID: 'actualID',
    clientSecret: 'actualSecret',
    returnURL: 'http://localhost:1337/auth/google/callback',
    callbackURL: 'http://localhost:1337/auth/google/callback',
    onSuccess:verifyHandler
    }, verifyHandler));

    app.use(passport.initialize());
    app.use(passport.session());
    }

    // Completely override Express middleware loading.
    // If you only want to override the bodyParser, cookieParser
    // or methodOverride middleware, see the appropriate keys below.
    // If you only want to override one or more of the default middleware,
    // but keep the order the same, use the middleware key.
    // See the http hook in the Sails core for the default loading order.
    //
    // loadMiddleware: function( app, defaultMiddleware, sails ) { ... }

    // Override one or more of the default middleware (besides bodyParser, cookieParser)
    //
    // middleware: {
    // session: false, // turn off session completely for HTTP requests
    // 404: function ( req, res, next ) { ... your custom 404 middleware ... }
    // }

    // The middleware function used for parsing the HTTP request body.
    // (this most commonly comes up in the context of file uploads)
    //
    // Defaults to a slightly modified version of express.bodyParser, i.e.:
    // If the Connect bodyParser doesn't understand the HTTP body request
    // data, Sails runs it again with an artificial header, forcing it to try
    // and parse the request body as JSON. (this allows JSON to be used as your
    // request data without the need to specify a 'Content-type: application/json'
    // header)
    //
    // If you want to change any of that, you can override the bodyParser with
    // your own custom middleware:
    // bodyParser: function customBodyParser (options) { ... return function(req, res, next) {...}; }
    //
    // Or you can always revert back to the vanilla parser built-in to Connect/Express:
    // bodyParser: require('express').bodyParser,
    //
    // Or to disable the body parser completely:
    // bodyParser: false,
    // (useful for streaming file uploads-- to disk or S3 or wherever you like)
    //
    // WARNING
    // ======================================================================
    // Multipart bodyParser (i.e. express.multipart() ) will be removed
    // in Connect 3 / Express 4.
    // Why?
    //
    // The multipart component of this parser will be replaced
    // in a subsequent version of Sails (after v0.10, probably v0.11) with:
    // file-parser
    // (or something comparable)
    //
    // If you understand the risks of using the multipart bodyParser,
    // and would like to disable the warning log messages, uncomment:
    // silenceMultipartWarning: true,
    // ======================================================================

    // Cookie parser middleware to use
    // (or false to disable)
    //
    // Defaults to express.cookieParser
    //
    // Example override:
    // cookieParser: (function customMethodOverride (req, res, next) {})(),

    // HTTP method override middleware
    // (or false to disable)
    //
    // This option allows artificial query params to be passed to trick
    // Sails into thinking a different HTTP verb was used.
    // Useful when supporting an API for user-agents which don't allow
    // PUT or DELETE requests
    //
    // Defaults to express.methodOverride
    //
    // Example override:
    // methodOverride: (function customMethodOverride (req, res, next) {})()
    };

/**

  • HTTP Flat-File Cache
    *

  • These settings are for Express' static middleware- the part that serves

  • flat-files like images, css, client-side templates, favicons, etc.
    *

  • In Sails, this affects the files in your app's assets directory.

  • By default, Sails uses your project's Gruntfile to compile/copy those

  • assets to .tmp/public, where they're accessible to Express.
    *

  • The HTTP static cache is only active in a 'production' environment,

  • since that's the only time Express will cache flat-files.
    *

  • For more information on configuration, check out:

  • http://sailsjs.org/#documentation
    */
    module.exports.cache = {

    // The number of seconds to cache files being served from disk
    // (only works in production mode)
    maxAge: 31557600000
    };

@stefanbuck
Copy link
Owner

Can you make the code available on GitHub? This would help me to understand your problem better.

@Mylab6
Copy link
Author

Mylab6 commented Oct 8, 2014

While I do plan to open source my project soon , it's not ready yet( I need to scrub for keys) .

I migrated a sails .9 to .10 , could this cause the problem ?

@stefanbuck
Copy link
Owner

Could be possible. They changed a lot from 0.9 to 0.10. But as your problem is not related to this example, i would close it. For general sails.js question, please visit http://sailsjs.org/#/support.

@Mylab6
Copy link
Author

Mylab6 commented Oct 9, 2014

Thanks !

I ended up using the passport sails package which simplified this a bit , thanks for your time .

Sent from my iPad

On Oct 8, 2014, at 3:08 AM, Stefan Buck notifications@github.com wrote:

Could be possible. They changed a lot from 0.9 to 0.10. But as your problem is not related to this example, i would close this issue. For general sails.js question, please visit http://sailsjs.org/#/support.


Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants