// Generated by CoffeeScript 1.3.3
(function() {
  var GoogleStrategy, passport;

  passport = require('passport');

  GoogleStrategy = (require('passport-google')).Strategy;

  exports.setup = function(baseUrl, app, findOrCreateUser, serializeUser, deserializeUser) {
    var googleConfig;
    googleConfig = {
      returnURL: baseUrl + 'auth/google/return',
      realm: baseUrl
    };
    passport.use(new GoogleStrategy(googleConfig, function(identifier, profile, done) {
      return findOrCreateUser(identifier, profile, function(err, user) {
        return done(err, user);
      });
    }));
    passport.serializeUser(serializeUser);
    passport.deserializeUser(deserializeUser);
    app.use(passport.initialize());
    app.use(passport.session());
    app.get('/auth/google', passport.authenticate('google'));
    app.get('/auth/google/return', passport.authenticate('google', {
      successRedirect: '/',
      failureRedirect: '/login'
    }));
    return passport;
  };

}).call(this);
