<commit_before>"use strict";

var authKeys = require('../config/auth'),
    User = require('./models/User'),
    passport = require('flatiron-passport'),
    FacebookStrategy = require('passport-facebook').Strategy,
    GoogleStrategy = require('passport-google').Strategy,
    GitHubStrategy = require('passport-github').Strategy;

function findOrCreateUser (profile, done) {
  return User.findOrCreate(profile).then(function (user) {
    done(user);
  }, function (err) {
    done(err);
  });
}

function userInfoCallback (strategy) {
  if (strategy == 'google') {
    return function (identifier, profile, done) {
      profile.id = identifier;
      profile.provider = strategy;

      return findOrCreateUser(profile, done);
    };
  }

  return function (token, tokenSecret, profile, done) {
    return findOrCreateUser(profile, done);
  };
}


var Config = {};

Config.strategies = ['facebook', 'google', 'github'];

Config.configure = function () {
  this.facebook();
  this.google();
  this.github();
  this.passportSession();
};

Config.strategyRoutes = function (defaultRouteHandler) {
  var routes = {},
      request = function (strategy) { return passport.authenticate(strategy); },
      response = function (strategy) {
        return passport.authenticate(strategy, {
          successRedirect: '/',
          failureRedirect: '/'
        });
      };

  this.strategies.forEach(function (strategy) {
    routes['/auth/' + strategy] = request(strategy);
    routes['/auth/' + strategy + '/callback'] = [response(strategy), defaultRouteHandler];
  });

  return routes;
};

Config.facebook = function () {
  passport.use(new FacebookStrategy({
      clientID:       authKeys.facebook.key,
      clientSecret:   authKeys.facebook.secret,
      callbackURL:    'http://0.0.0.0:5000/auth/facebook/callback'<commit_msg>Request email from facebook<commit_after>"use strict";

var authKeys = require('../config/auth'),
    User = require('./models/User'),
    passport = require('flatiron-passport'),
    FacebookStrategy = require('passport-facebook').Strategy,
    GoogleStrategy = require('passport-google').Strategy,
    GitHubStrategy = require('passport-github').Strategy;

function findOrCreateUser (profile, done) {
  return User.findOrCreate(profile).then(function (user) {
    done(user);
  }, function (err) {
    done(err);
  });
}

function userInfoCallback (strategy) {
  if (strategy == 'google') {
    return function (identifier, profile, done) {
      profile.id = identifier;
      profile.provider = strategy;

      return findOrCreateUser(profile, done);
    };
  }

  return function (token, tokenSecret, profile, done) {
    return findOrCreateUser(profile, done);
  };
}


var Config = {};

Config.strategies = ['facebook', 'google', 'github'];

Config.strategyOptions = {
  facebook: { scope: 'email' }
};

Config.configure = function () {
  this.facebook();
  this.google();
  this.github();
  this.passportSession();
};

Config.strategyRoutes = function (defaultRouteHandler) {
  var routes = {},
      request = function (strategy) { return passport.authenticate(strategy, Config.strategyOptions[strategy]); },
      response = function (strategy) {
        return passport.authenticate(strategy, {
          successRedirect: '/',
          failureRedirect: '/'
        });
      };

  this.strategies.forEach(function (strategy) {
    routes['/auth/' + strategy] = request(strategy);
    routes['/auth/' + strategy + '/callback'] = [response(strategy), defaultRouteHandler];
  });

  return routes;
};

Config.facebook = function () {
  passport.use(new FacebookStrategy({
      clientID:       authKeys.facebook.key,
      clientSecret:   authKeys.facebook.secret,
      callbackURL:    'http://0.0.0.0:5000/auth/facebook/callback'
{'fraction_non_alphanumeric': 0.15031813361611876, 'fraction_numerical': 0.0042417815482502655, 'mean_word_length': 3.5844471445929527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5290862', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1092, 'n_words': 215}