<commit_before>'use strict';

let jwt = require('./jwt');
let config = require('config');
let passport = require('passport');

module.exports = {
  setProvider: function(options) {

    options.authenticate = options.authenticate || options.provider;

    passport.use(new options.Strategy(config.providers[options.provider], function() {
      let args = Array.prototype.slice.call(arguments);
      let profile = args[args.length - 2];
      let done = args[args.length - 1];
      return done(null, {
        id: profile.id,
        provider: options.provider
      });
    }));

    options.app.get(
      '/auth/' + options.provider,
      function setRedirect(req, res, next) {
        let referrer = config.referrers[req.get('Referrer')];
        if (!referer) {
          res.status(400).send('bad request');
          return;
        }
        req.session.referrer = referer;
        next();
      },
      passport.authenticate(options.authenticate, options.options)
    );

    options.app.get('/auth/' + options.provider + '/callback', function(req, res, next) {
      if (!req.session.referrer) {
        res.status(400).send('bad request');
        return;
      }
      passport.authenticate(options.authenticate, function(err, profile, info) {
        let referrer = req.session.referrer;
        req.session.destroy();
        if (err || !profile) {
          res.redirect(referrer.errorRedirect);
          return;
        }
				let jwtToken = jwt.getToken({ profile, secret: referrer.secret });
        res.redirect(referer.successRedirect + '?jwt=' + jwtToken);
      })(req, res, next);
    });

  }
};<commit_msg>formatting<commit_after>'use strict';

let jwt = require('./jwt');
let config = require('config');
let passport = require('passport');

module.exports = {
  setProvider: function(options) {

    options.authenticate = options.authenticate || options.provider;

    passport.use(new options.Strategy(config.providers[options.provider], function() {
      let args = Array.prototype.slice.call(arguments);
      let profile = args[args.length - 2];
      let done = args[args.length - 1];
      return done(null, {
        id: profile.id,
        provider: options.provider
      });
    }));

    options.app.get(
      '/auth/' + options.provider,
      function setRedirect(req, res, next) {
        let referrer = config.referrers[req.get('Referrer')];
        if (!referer) {
          res.status(400).send('bad request');
          return;
        }
        req.session.referrer = referer;
        next();
      },
      passport.authenticate(options.authenticate, options.options)
    );

    options.app.get('/auth/' + options.provider + '/callback', function(req, res, next) {
      if (!req.session.referrer) {
        res.status(400).send('bad request');
        return;
      }
      passport.authenticate(options.authenticate, function(err, profile, info) {
        let referrer = req.session.referrer;
        req.session.destroy();
        if (err || !profile) {
          res.redirect(referrer.errorRedirect);
          return;
        }
        let jwtToken = jwt.getToken({
          profile, secret: referrer.secret
        });
        res.redirect(referer.successRedirect + '?jwt=' + jwtToken);
      })(req, res, next);
    });

  }
};
{'fraction_non_alphanumeric': 0.1483733657646701, 'fraction_numerical': 0.00486470051687443, 'mean_word_length': 2.4741288278775078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4401746', 'n_tokens_mistral': 1001, 'n_tokens_neox': 973, 'n_words': 186}