<commit_before>var request = require('request');
var qs      = require('querystring');

module.exports = function slackOAuth(server) {

  	server.get('/auth/slack', function(req, res){
		
  		var client_id     = process.env.SLACK_CLIENT_ID;
  		var client_secret = process.env.SLACK_CLIENT_SECRET;
  		var redirect_uri  = process.env.SLACK_REDIRECT_URI;  //'http://localhost:3000/auth/slack';
  		var url           = 'https://slack.com/api/oauth.access';
  		var error         = req.query.error;
  		var code          = req.query.code;
  		var state         = req.query.state;

  		if (!error) {
  			var query = {
  				client_id: client_id,
  				client_secret: client_secret,
  				code: code,
  				redirect_uri: redirect_uri
  			}

  			request
	  			.get({url: url + '?' + qs.stringify(query), json: true}, function (error, response, body) {
	  	        var token = response.body;
              var externalToken = {};
              state = state.split(".");

              externalToken.provider = 'slack';
              externalToken.token = token.access_token;
	  	        externalToken.scope = token.scope;
	  	        
  	  	      server.models.Account.findById(state[1], function(err, account) {
  	  	        if (err) {
                  res.send(err); // No account found
                } 
  	  	        
                externalToken.accountId = account.id;
                externalToken.userId = state[0];

  	  	        server.models.externalProviderToken.create(externalToken, function() {
                  res.redirect(301, '/#/authorized');
  	  	        });
  	  	      });			
	  				})
        		.on('error', function(err) {
        			console.log(err);
        			res.send(err);
        		});
  		}
	});
};<commit_msg>Added extra information to slack-auth<commit_after>var request = require('request');
var qs      = require('querystring');

module.exports = function slackOAuth(server) {

    server.get('/auth/slack', function(req, res) {

        var client_id     = process.env.SLACK_CLIENT_ID;
        var client_secret = process.env.SLACK_CLIENT_SECRET;
        var redirect_uri  = process.env.SLACK_REDIRECT_URI;  //'http://localhost:3000/auth/slack';
        var urlAccess     = 'https://slack.com/api/oauth.access';
        var urlTest       = 'https://slack.com/api/auth.test';
        var error         = req.query.error;
        var code          = req.query.code;
        var state         = req.query.state;

        if (!error) {
            var query = {
                client_id: client_id,
                client_secret: client_secret,
                code: code,
                redirect_uri: redirect_uri
            }

            request
                .get({url: urlAccess + '?' + qs.stringify(query), json: true}, function (error, response, body) {
                    var token = response.body;
                    var externalToken = {};
                    state = state.split(".");

                    externalToken.provider = 'slack';
                    externalToken.token = token.access_token;
                    externalToken.scope = token.scope;

                    server.models.Account.findById(state[1], function(err, account) {
                        if (err) {
                            res.send(err); // No account found
                        }

                        externalToken.accountId = account.id;

                        request
                            .get({url: urlTest + '?' + qs.stringify({ token: externalToken.token }), json: true}, function (error, response, body) {
                                var extraInfo = response.body;

                                externalToken.url    = extraInfo.url;
                                externalToken.team   = extraInfo.team;
                                externalToken.user   = extraInfo.user;
                                externalToken.teamId = extraInfo.team_id;
                                externalToken.userId = extraInfo.user_id;

                                server.models.externalProviderToken.create(externalToken, function() {
                                    res.redirect(301, '/#/authorized');
                                });
                            });


                    });
            })
            .on('error', function(err) {
                console.log(err);
                res.send(err);
            });
        }
    });
};
{'fraction_non_alphanumeric': 0.11319900384876613, 'fraction_numerical': 0.0038487661308580483, 'mean_word_length': 1.379106085083468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '891461', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1201, 'n_words': 210}