<commit_before>/*
 * Bearer Authentication Protocol
 *
 * Bearer Authentication is for authorizing API requests. Once
 * a user is created, a token is also generated for that user
 * in its passport. This token can be used to authenticate
 * API requests.
 *
 */

module.exports = function(token, done) {

  sails.models.passport.findOne({ accessToken: token }, function(err, passport) {
    if (err) {
      return done(err);
    }

    if (!passport) {
      return done(null, false);
    }

    sails.models.user.findOneById(passport.user, function(err, user) {
      if (err) {
        return done(err);
      }

      if (!user) {
        return done(null, false);
      }

      return done(null, user, { scope: 'all' });
    });<commit_msg>fix receiving req param and delete access token from params<commit_after>/*
 * Bearer Authentication Protocol
 *
 * Bearer Authentication is for authorizing API requests. Once
 * a user is created, a token is also generated for that user
 * in its passport. This token can be used to authenticate
 * API requests.
 *
 */

module.exports = function(req, token, done) {

  sails.models.passport.findOne({ accessToken: token }, function(err, passport) {
    if (err) {
      return done(err);
    }

    if (!passport) {
      return done(null, false);
    }

    sails.models.user.findOneById(passport.user, function(err, user) {
      if (err) {
        return done(err);
      }

      if (!user) {
        return done(null, false);
      }

      // delete access_token from params
      // to avoid conflicts with blueprints query builder
      delete req.query.access_token;
      return done(null, user, { scope: 'all' });
    });
{'fraction_non_alphanumeric': 0.11302795954788816, 'fraction_numerical': 0.0, 'mean_word_length': 2.6724890829694323, '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': '4905350', 'n_tokens_mistral': 509, 'n_tokens_neox': 490, 'n_words': 163}