<commit_before>'use strict';

const dotenv = require('dotenv');
dotenv.load()

const passport = require('./config/passport');
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const app = express();
const request = require('request');

app.use(bodyParser.urlencoded({
  extended: true
}));
app.use(cookieParser());
app.use(session({
  secret: 'foo',
  resave: true,
  saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.set('view engine', 'ejs');

app.get('/', function(req, res) {
  res.redirect('/login');
});

app.post('/login/callback',
  function(req, res, next) {
    if (!req.user) {
      passport.authenticate('saml')(req, res, next);
    } else {
      passport.authorize('saml')(req, res, next);
    }
  },
  function(req, res) {
    if (req.account) {
      // console.log(req.account);
      // let tenant                  = process.env.AUTH0_DOMAIN;
      // let primary_account_user_id = req.user.id; // should be something like this

      // request({
      //     url: 'https://' + tenant + '.auth0.com/api/v2/users/' + primary_account_user_id + '/identities', //URL to hit
      //     method: 'POST',
      //     body: {
      //       // provider: 
      //       // user_id:
      //     },
      // }, function(error, response, body){
      //     if(error) {
      //         console.log(error);
      //     } else {
      //         console.log(response.statusCode, body);
      //     }
      // });
    }
    if (req.user) {
      let result = {
        user: req.user,
        account: req.account
      };
      res.render('index', result);
    } else {
      res.redirect('/login');
    }
  }
);

app.get('/login',
  passport.authenticate('saml')
);

app.listen(3000, function() {
  console.log('Listening on port 3000');
});
<commit_msg>Improved request and dependencies<commit_after>'use strict';

const dotenv = require('dotenv');
dotenv.load()

const passport = require('./config/passport');
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const app = express();
const request = require('request');

app.use(bodyParser.urlencoded({
  extended: true
}));
app.use(cookieParser());
app.use(session({
  secret: 'foo',
  resave: true,
  saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.set('view engine', 'ejs');

app.get('/', function(req, res) {
  res.redirect('/login');
});

app.post('/login/callback',
  function(req, res, next) {
    if (!req.user) {
      passport.authenticate('saml')(req, res, next);
    } else {
      passport.authorize('saml')(req, res, next);
    }
  },
  function(req, res) {
    if (req.account) {
      console.log(req.account);
      let tenant                  = process.env.AUTH0_DOMAIN;
      let apiv2_token             = process.env.AUTH0_APIV2_TOKEN;
      let primary_account_user_id = encodeURIComponent(req.user.user_id); 

      request({
          url: 'https://' + tenant + '.auth0.com/api/v2/users/' + primary_account_user_id + '/identities', //URL to hit
          method: 'POST',
          headers: {Authorization: 'Bearer ' + apiv2_token },
          json: {
            provider: req.account.provider,
            user_id: req.account.user_id
          },
      }, function(error, response, body){
          console.log(body);
          if(error) {
              console.log(error);
          } else { 
              console.log(response.statusCode.toString(), body);
          }
      });
    }
    if (req.user) {
      let result = {
        user: req.user,
        account: req.account
      };
      res.render('index', result);
    } else {
      res.redirect('/login');
    }
  }
);

app.get('/login',
  passport.authenticate('saml')
);

app.listen(3000, function() {
  console.log('Listening on port 3000');
});

{'fraction_non_alphanumeric': 0.17613495410568097, 'fraction_numerical': 0.0064500124038700075, 'mean_word_length': 2.5121951219512195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '150669', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1278, 'n_words': 246}