<commit_before>/**
 * TODO err - user deletes Sinopia token
 */
var crypto = require('crypto');
var GitHubApi = require('github');


function Auth(config, stuff) {
	if (!(this instanceof Auth)) {
		return new Auth(config, stuff);
	}

	this._org = config.org;
	this._clientID = config.client_id;
	this._clientSecret = config.client_secret;
	this._ttl = config.ttl * 1000; // sec -> ms
	
	this._logger = stuff.logger;
	this._userCache = Object.create(null);
}

Auth.prototype.authenticate = function(username, password, done) {
	this._getTeams(username, password, done);
};

Auth.prototype.add_user = function(username, password, done) {
	getTeams(username, password, function (err) {
		if (err) {
			return done(err);
		}
		done(null, true);
	});
};

Auth.prototype._getCache = function (username, password) {
	var shasum = crypto.createHash('sha1');
	shasum.update(JSON.stringify({
		username: username,
		password: password
	}));
	var token = shasum.digest('hex');
	if (!this._userCache[token]) {
		this._userCache[token] = Object.create(null);
	}
	return this._userCache[token]; 
}

Auth.prototype._getTeams = function (username, password, done) {
	var org = this._org;
	var logger = this._logger;
	var ttl = this._ttl;
	var cache = this._getCache(username, password);
	if (cache.groups && Date.now() < cache.expires) {
		return done(null, cache.groups);
	}
	if (!cache.github) {
		cache.github = new GitHubApi({
			version: "3.0.0"<commit_msg>classiest<commit_after>/**
 * TODO err - user deletes Sinopia token
 */
var crypto = require('crypto');
var GitHubApi = require('github');


function Auth(config, stuff) {
	if (!(this instanceof Auth)) {
		return new Auth(config, stuff);
	}

	this._org = config.org;
	this._clientID = config.client_id;
	this._clientSecret = config.client_secret;
	this._ttl = config.ttl * 1000; // sec -> ms
	
	this._logger = stuff.logger;
	this._userCache = Object.create(null);
}

Auth.prototype.authenticate = function(username, password, done) {
	this._getTeams(username, password, done);
};

Auth.prototype.add_user = function(username, password, done) {
	this._getTeams(username, password, function (err) {
		if (err) {
			return done(err);
		}
		done(null, true);
	});
};

Auth.prototype._getCache = function (username, password) {
	var shasum = crypto.createHash('sha1');
	shasum.update(JSON.stringify({
		username: username,
		password: password
	}));
	var token = shasum.digest('hex');
	if (!this._userCache[token]) {
		this._userCache[token] = Object.create(null);
	}
	return this._userCache[token]; 
}

Auth.prototype._getTeams = function (username, password, done) {
	var org = this._org;
	var logger = this._logger;
	var ttl = this._ttl;
	var cache = this._getCache(username, password);
	if (cache.groups && Date.now() < cache.expires) {
		return done(null, cache.groups);
	}
	if (!cache.github) {
		cache.github = new GitHubApi({
			version: "3.0.0"
{'fraction_non_alphanumeric': 0.1544574982722875, 'fraction_numerical': 0.0055286800276434, 'mean_word_length': 4.361111111111111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2662666', 'n_tokens_mistral': 1032, 'n_tokens_neox': 979, 'n_words': 225}