2015-11-27 14:28:31 +08:00
|
|
|
var SteamCommunity = require('../index.js');
|
|
|
|
|
2015-12-03 10:35:35 +08:00
|
|
|
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
|
|
|
var self = this;
|
2016-03-05 07:26:47 +08:00
|
|
|
this.httpRequest({
|
2016-09-02 03:05:46 +08:00
|
|
|
"uri": "https://steamcommunity.com/dev/apikey?l=english",
|
2015-12-03 10:35:35 +08:00
|
|
|
"followRedirect": false
|
|
|
|
}, function(err, response, body) {
|
2016-03-05 12:59:49 +08:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
2015-12-03 10:35:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(body.match(/<h2>Access Denied<\/h2>/)) {
|
|
|
|
return callback(new Error("Access Denied"));
|
|
|
|
}
|
|
|
|
|
|
|
|
var match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
|
|
|
|
if(match) {
|
|
|
|
// We already have an API key registered
|
|
|
|
callback(null, match[1]);
|
|
|
|
} else {
|
|
|
|
// We need to register a new API key
|
2016-09-02 03:05:46 +08:00
|
|
|
self.httpRequestPost('https://steamcommunity.com/dev/registerkey?l=english', {
|
2015-12-03 10:35:35 +08:00
|
|
|
"form": {
|
|
|
|
"domain": domain,
|
|
|
|
"agreeToTerms": "agreed",
|
|
|
|
"sessionid": self.getSessionID(),
|
|
|
|
"Submit": "Register"
|
|
|
|
}
|
|
|
|
}, function(err, response, body) {
|
2016-03-05 12:59:49 +08:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
2015-12-03 10:35:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.getWebApiKey(domain, callback);
|
2016-03-05 08:35:04 +08:00
|
|
|
}, "steamcommunity");
|
2015-12-03 10:35:35 +08:00
|
|
|
}
|
2016-03-05 08:35:04 +08:00
|
|
|
}, "steamcommunity");
|
2015-12-03 10:35:35 +08:00
|
|
|
};
|
|
|
|
|
2015-11-27 14:28:31 +08:00
|
|
|
SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
|
|
|
|
var self = this;
|
|
|
|
|
2015-12-01 09:39:55 +08:00
|
|
|
if( this.oAuthToken ) {
|
|
|
|
return callback( null, this.oAuthToken );
|
|
|
|
}
|
|
|
|
|
2015-11-27 14:28:31 +08:00
|
|
|
// Pull an oauth token from the webchat UI
|
2016-03-05 07:26:47 +08:00
|
|
|
this.httpRequest("https://steamcommunity.com/chat", function(err, response, body) {
|
2016-03-05 12:59:49 +08:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
2015-12-01 08:40:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-27 14:28:31 +08:00
|
|
|
var match = body.match(/"([0-9a-f]{32})"/);
|
|
|
|
if (!match) {
|
|
|
|
callback(new Error("Malformed response"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(null, match[1]);
|
2016-03-05 08:35:04 +08:00
|
|
|
}, "steamcommunity");
|
2015-11-27 14:28:31 +08:00
|
|
|
};
|