{"size": 634, "ext": "js", "max_stars_repo_path": "swift_auth.js", "max_stars_repo_name": "Samze/docker-registry-swift-gc", "max_stars_repo_stars_event_min_datetime": "2015-02-17T14:58:40.000Z", "max_stars_repo_stars_event_max_datetime": "2015-02-17T14:58:40.000Z", "max_issues_repo_path": "swift_auth.js", "max_issues_repo_name": "Samze/docker-registry-swift-gc", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "swift_auth.js", "max_forks_repo_name": "Samze/docker-registry-swift-gc", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.4516129032, "max_line_length": 49, "alphanum_fraction": 0.6072555205}
'use strict';

var request = require('request'),
 	Q = require('q'),
 	authenticate = {};

module.exports = function(authurl, user, key){
	return function(){
		var deferred = Q.defer();

		request(
		{
			method: 'GET',
			uri: authurl,
			headers: {
				'X-Auth-User': user,
				'X-Auth-Key':key
			}
		}, function(error,response,body){
			if(!error && response.statusCode == 200){
				var token = response.headers["x-auth-token"];
				var url = response.headers["x-storage-url"];
				deferred.resolve({token:token,url:url});
			} else {
				console.log(error);
				deferred.reject(error);
			}
		});
		return deferred.promise;
	}
};