<commit_before>var Express = require('express');
var Webtask = require('webtask-tools');
var jwt = require('jsonwebtoken');

var app = Express();

var bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({ extended: false }));

var Promise = require('bluebird');
var request = Promise.promisify(require('request'));

app.get('/', function (req, res) {
  var token = req.query.token;

  jwt.verify(token, new Buffer(req.webtaskContext.data.client_secret,'base64'), function(err, decoded) {

    if (err) {
      res.end('error');
      return;
    }

    var slack_username = decoded.slack_username;
    var slack_enrolled = decoded.slack_enrolled;
    var slackApiToken = req.webtaskContext.data.slack_token;

    if (slack_username && !!slack_enrolled)  {
      sendUrlToSlack(req, res, token, slackApiToken, slack_username);
    } else {
      showEnrollmentStep(res, req.webtaskContext, token, slack_username);
    }
  });
});

app.post('/', function (req, res) {
  var token = req.body.token;

  jwt.verify(token, new Buffer(req.webtaskContext.data.client_secret, 'base64'), function (err, decoded) {
    if (err) {
      res.end('error on enrollment token verification');
      return;
    }

    var slack_username = req.body.slack_username;
    var slackApiToken = req.webtaskContext.data.slack_token;
    if (slack_username) {
      startMfaEnrollment(req.webtaskContext, decoded.sub, slack_username);
      sendUrlToSlack(req, res, token, slackApiToken, slack_username);
    }
  });
});

app.get('/verify', function (req, res) {
  var token = req.query.token;

  jwt.verify(token, new Buffer(req.webtaskContext.data.client_secret, 'base64'), function(err, decoded) {

    if (err) {
      res.end('error on callback token verification');
      return;
    }

    completeMfaEnrollment(req.webtaskContext, decoded.sub);
    redirectBack(res, req.webtaskContext, decoded, true);
  });
});

function hereDoc(f) {
  return f.toString().
    replace(/^[^\/]+\/\*!?/, '').
    replace(/\*\/[^\/]+$/, '');
}

function redirectBack(res, webtaskContext, decoded, success) {
  var token = jwt.sign({
      status: success ? 'ok' : 'fail'
    },
    new Buffer(webtaskContext.data.client_secret, 'base64'),
    {
      subject: decoded.sub,
      expiresInMinutes: 30,
      audience: decoded.aud,
      issuer: 'urn:sgmeyer:slack:mfa'
    });<commit_msg>Syncing expiresInMinutes between rule and web task.<commit_after>var Express = require('express');
var Webtask = require('webtask-tools');
var jwt = require('jsonwebtoken');

var app = Express();

var bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({ extended: false }));

var Promise = require('bluebird');
var request = Promise.promisify(require('request'));

app.get('/', function (req, res) {
  var token = req.query.token;

  jwt.verify(token, new Buffer(req.webtaskContext.data.client_secret,'base64'), function(err, decoded) {

    if (err) {
      res.end('error');
      return;
    }

    var slack_username = decoded.slack_username;
    var slack_enrolled = decoded.slack_enrolled;
    var slackApiToken = req.webtaskContext.data.slack_token;

    if (slack_username && !!slack_enrolled)  {
      sendUrlToSlack(req, res, token, slackApiToken, slack_username);
    } else {
      showEnrollmentStep(res, req.webtaskContext, token, slack_username);
    }
  });
});

app.post('/', function (req, res) {
  var token = req.body.token;

  jwt.verify(token, new Buffer(req.webtaskContext.data.client_secret, 'base64'), function (err, decoded) {
    if (err) {
      res.end('error on enrollment token verification');
      return;
    }

    var slack_username = req.body.slack_username;
    var slackApiToken = req.webtaskContext.data.slack_token;
    if (slack_username) {
      startMfaEnrollment(req.webtaskContext, decoded.sub, slack_username);
      sendUrlToSlack(req, res, token, slackApiToken, slack_username);
    }
  });
});

app.get('/verify', function (req, res) {
  var token = req.query.token;

  jwt.verify(token, new Buffer(req.webtaskContext.data.client_secret, 'base64'), function(err, decoded) {

    if (err) {
      res.end('error on callback token verification');
      return;
    }

    completeMfaEnrollment(req.webtaskContext, decoded.sub);
    redirectBack(res, req.webtaskContext, decoded, true);
  });
});

function hereDoc(f) {
  return f.toString().
    replace(/^[^\/]+\/\*!?/, '').
    replace(/\*\/[^\/]+$/, '');
}

function redirectBack(res, webtaskContext, decoded, success) {
  var token = jwt.sign({
      status: success ? 'ok' : 'fail'
    },
    new Buffer(webtaskContext.data.client_secret, 'base64'),
    {
      subject: decoded.sub,
      expiresInMinutes: 15,
      audience: decoded.aud,
      issuer: 'urn:sgmeyer:slack:mfa'
    });
{'fraction_non_alphanumeric': 0.15395894428152493, 'fraction_numerical': 0.0041893590280687055, 'mean_word_length': 3.699803149606299, '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': '447624', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1594, 'n_words': 318}