<commit_before>/**
 * Passport configuration file where you should configure all your strategies
 * @description :: Configuration file where you configure your passport authentication
 */

var _ = require('lodash');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var JwtStrategy = require('passport-jwt').Strategy;
var FacebookTokenStrategy = require('passport-facebook-token').Strategy;
var TwitterTokenStrategy = require('passport-twitter-token').Strategy;
var VKontakteTokenStrategy = require('passport-vkontakte-token').Strategy;
var FoursquareTokenStrategy = require('passport-foursquare-token').Strategy;
var GitHubTokenStrategy = require('passport-github-token').Strategy;
var InstagramTokenStrategy = require('passport-instagram-token').Strategy;
var PayPalTokenStrategy = require('passport-paypal-token').Strategy;
var RedditTokenStrategy = require('passport-reddit-token').Strategy;
var SoundCloudTokenStrategy = require('passport-soundcloud-token').Strategy;
var WindowsLiveTokenStrategy = require('passport-windows-live-token').Strategy;
var TwitchTokenStrategy = require('passport-twitch-token').Strategy;
var YandexTokenStrategy = require('passport-yandex-token').Strategy;
var AmazonTokenStrategy = require('passport-amazon-token').Strategy;
var GooglePlusTokenStrategy = require('passport-google-plus-token').Strategy;
var YahooTokenStrategy = require('passport-yahoo-token').Strategy;

// TODO: make this more stable and properly parse profile data

/**
 * Configuration object for local strategy
 * @type {Object}
 * @private
 */
var LOCAL_STRATEGY_CONFIG = {
  usernameField: 'email',
  passwordField: 'password',
  session: false,
  passReqToCallback: true
};

/**
 * Configuration object for JWT strategy
 * @type {Object}
 * @private
 */
var JWT_STRATEGY_CONFIG = {
  secretOrKey: "<%= answers['application:secret'] %>",
  tokenBodyField: 'access_token',
  authScheme: 'Bearer',
  passReqToCallback: true
};

/**
 * Configuration object for social strategies
 * @type {Object}
 * @private
 */
var SOCIAL_STRATEGY_CONFIG = {
  clientID: '-',
  clientSecret: '-',
  consumerKey: '-',
  consumerSecret: '-',
  passReqToCallback: true
};

/**
 * Triggers when user authenticates via local strategy
 * @param {Object} req Request object
 * @param {String} email Email from body field in request
 * @param {String} password Password from body field in request
 * @param {Function} next Callback
 * @private
 */
function _onLocalStrategyAuth(req, email, password, next) {
  User
    .findOne({email: email})
    .then(function (user) {
      if (!user) return next(null, null, {
        code: 'E_USER_NOT_FOUND',
        message: email + ' is not found'
      });

      if (!HashService.bcrypt.compareSync(password, user.password)) return next(null, null, {
        code: 'E_WRONG_PASSWORD',
        message: 'Password is wrong'
      });

      return next(null, user, {});
    })
    .catch(next);
}

/**
 * Triggers when user authenticates via JWT strategy
 * @param {Object} req Request object
 * @param {Object} payload Decoded payload from JWT
 * @param {Function} next Callback
 * @private
 */
function _onJwtStrategyAuth(req, payload, next) {
  User
    .findOne({id: payload.id})
    .exec(function (error, user) {
      if (error) return next(error, false, {});
      if (!user) return next(null, false, {
        code: 'E_USER_NOT_FOUND',
        message: 'User with that JWT not found'
      });

      return next(null, user, {});
    });
}
<commit_msg>Update config for passport jwt strategy<commit_after>/**
 * Passport configuration file where you should configure all your strategies
 * @description :: Configuration file where you configure your passport authentication
 */

var _ = require('lodash');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var JwtStrategy = require('passport-jwt').Strategy;
var FacebookTokenStrategy = require('passport-facebook-token').Strategy;
var TwitterTokenStrategy = require('passport-twitter-token').Strategy;
var VKontakteTokenStrategy = require('passport-vkontakte-token').Strategy;
var FoursquareTokenStrategy = require('passport-foursquare-token').Strategy;
var GitHubTokenStrategy = require('passport-github-token').Strategy;
var InstagramTokenStrategy = require('passport-instagram-token').Strategy;
var PayPalTokenStrategy = require('passport-paypal-token').Strategy;
var RedditTokenStrategy = require('passport-reddit-token').Strategy;
var SoundCloudTokenStrategy = require('passport-soundcloud-token').Strategy;
var WindowsLiveTokenStrategy = require('passport-windows-live-token').Strategy;
var TwitchTokenStrategy = require('passport-twitch-token').Strategy;
var YandexTokenStrategy = require('passport-yandex-token').Strategy;
var AmazonTokenStrategy = require('passport-amazon-token').Strategy;
var GooglePlusTokenStrategy = require('passport-google-plus-token').Strategy;
var YahooTokenStrategy = require('passport-yahoo-token').Strategy;

// TODO: make this more stable and properly parse profile data

/**
 * Configuration object for local strategy
 * @type {Object}
 * @private
 */
var LOCAL_STRATEGY_CONFIG = {
  usernameField: 'email',
  passwordField: 'password',
  session: false,
  passReqToCallback: true
};

/**
 * Configuration object for JWT strategy
 * @type {Object}
 * @private
 */
var JWT_STRATEGY_CONFIG = {
  secretOrKey: "<%= answers['application:secret'] %>",
  tokenBodyField: 'access_token',
  tokenQueryParameterName: 'access_token',
  authScheme: 'Bearer',
  session: false,
  passReqToCallback: true
};

/**
 * Configuration object for social strategies
 * @type {Object}
 * @private
 */
var SOCIAL_STRATEGY_CONFIG = {
  clientID: '-',
  clientSecret: '-',
  consumerKey: '-',
  consumerSecret: '-',
  passReqToCallback: true
};

/**
 * Triggers when user authenticates via local strategy
 * @param {Object} req Request object
 * @param {String} email Email from body field in request
 * @param {String} password Password from body field in request
 * @param {Function} next Callback
 * @private
 */
function _onLocalStrategyAuth(req, email, password, next) {
  User
    .findOne({email: email})
    .then(function (user) {
      if (!user) return next(null, null, {
        code: 'E_USER_NOT_FOUND',
        message: email + ' is not found'
      });

      if (!HashService.bcrypt.compareSync(password, user.password)) return next(null, null, {
        code: 'E_WRONG_PASSWORD',
        message: 'Password is wrong'
      });

      return next(null, user, {});
    })
    .catch(next);
}

/**
 * Triggers when user authenticates via JWT strategy
 * @param {Object} req Request object
 * @param {Object} payload Decoded payload from JWT
 * @param {Function} next Callback
 * @private
 */
function _onJwtStrategyAuth(req, payload, next) {
  User
    .findOne({id: payload.id})
    .then(function (user) {
      if (!user) return next(null, null, {
        code: 'E_USER_NOT_FOUND',
        message: 'User with that JWT not found'
      });

      return next(null, user, {});
    })
    .catch(next);
}

{'fraction_non_alphanumeric': 0.12799211489721204, 'fraction_numerical': 0.0, 'mean_word_length': 4.588512981904013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '241932', 'n_tokens_mistral': 2052, 'n_tokens_neox': 2026, 'n_words': 538}