<commit_before>'use strict';

var consts = require('../constants');
function configure (env) {
    function verifyAuthorization(req, res, next) {
        // Retrieve the secret values to be compared.
        var api_secret = env.api_secret;
        var secret = req.params.secret ? req.params.secret : req.header('api-secret');

        // Return an error message if the authorization fails.
        var authorized = (api_secret && api_secret.length > 12) ? (secret === api_secret) : false;
        if (!authorized) {
            res.sendJSONStatus(res, consts.HTTP_UNAUTHORIZED, 'Unauthorized', 'api-secret Request Header is incorrect or missing.');
        } else {
            next();
        }

        return authorized;
    }
    return verifyAuthorization;

}
module.exports = configure;<commit_msg>allow the api secret to be included in the post body<commit_after>'use strict';

var _ = require('lodash');
var consts = require('../constants');

function configure (env) {
    function verifyAuthorization(req, res, next) {
        // Retrieve the secret values to be compared.
        var api_secret = env.api_secret;

        var secret = req.params.secret ? req.params.secret : req.header('api-secret');

        // try to get the scret from the body, but don't leave it there
        if (!secret && req.body) {
          if (_.isArray(req.body) && req.body.length > 0) {
            secret = req.body[0].secret;
            delete req.body[0].secret;
          } else {
            secret = req.body.secret;
            delete req.body.secret;
          }
        }

        // Return an error message if the authorization fails.
        var authorized = (api_secret && api_secret.length > 12) ? (secret === api_secret) : false;
        if (!authorized) {
            res.sendJSONStatus(res, consts.HTTP_UNAUTHORIZED, 'Unauthorized', 'api-secret Request Header is incorrect or missing.');
        } else {
            next();
        }

        return authorized;
    }
    return verifyAuthorization;

}
module.exports = configure;
{'fraction_non_alphanumeric': 0.11502692119432208, 'fraction_numerical': 0.0034263338228095936, 'mean_word_length': 2.3398692810457518, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '1857208', 'n_tokens_mistral': 564, 'n_tokens_neox': 558, 'n_words': 166}