<commit_before>var VError, request, async, uri;

VError = require('verror');
request = require('request');
async = require('async');

/**
 * @method
 * @summary Setups default base uri
 *
 * @param {String} newUri
 */
exports.configUri = function (newUri) {
  'use strict';
  
  uri = newUri;
};<commit_msg>comunication with auth server<commit_after>var VError, httpRequest, async, uri;
VError = require('verror');
httpRequest = require('request');
async = require('async');

exports.configUri = function (newUri) {
  'use strict';

  uri = newUri;
};

exports.session = function authSession() {
  'use strict';

  return function authSessionMiddleware(request, response, next) {
    var token;
    token = request.get('csrf-token');
    httpRequest({
      'url'     : uri + '/users/me',
      'headers' : {'csrf-token' : token}
    }, function (error, res, body) {
      var user;
      if (error) {
        return next(error);
      }
      try {
        user = JSON.parse(body);
        request.session = user;
        return next();
      } catch (error) {
        return next(error);
      }
    });
  };
};

exports.can = function authCan(permission) {
  'use strict';

  return function authPermissionMiddleware(request, response, next) {
    var session;
    session = request.session;
    if (!session || session.profile.permissions.lastIndexOf(permission) === -1) {
      return response.status(403).end();
    }
    return next();
  };
};
{'fraction_non_alphanumeric': 0.1510344827586207, 'fraction_numerical': 0.002758620689655172, 'mean_word_length': 3.0758426966292136, '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': '150614', 'n_tokens_mistral': 448, 'n_tokens_neox': 444, 'n_words': 112}