Compare commits

...

49 Commits

Author SHA1 Message Date
Alexander Corn
e446cc3cd8 3.18.2 2016-01-18 18:47:02 -05:00
Alexander Corn
722ca6689b Removed excess whitespace 2016-01-18 18:46:45 -05:00
Alexander Corn
1276c71e4e Use same device ID for all trade confirmation requests 2016-01-18 18:38:50 -05:00
Alexander Corn
a51bd21153 3.18.1 2016-01-17 19:19:14 -05:00
Alexander Corn
f1bbfc4901 Removed unused arguments from CSteamGroup#deleteAnnouncement 2016-01-17 19:19:04 -05:00
Alexander Corn
eb8d094bf1 3.18.0 2016-01-17 19:10:02 -05:00
Alexander Corn
b1cca95ec0 Merge pull request #70 from LeCoffee/master
Adding ability to edit an annoucement.
2016-01-17 19:08:20 -05:00
Shaun Barratt
27ef78cc4b Added ability to deleteAnnoucement 2016-01-17 02:27:11 +00:00
Shaun Barratt
4223d88fd1 Catching HTTP errors properly
Specifying the Group in getAllGroupAnnouncements
Removing unnecessary comments
Made the callback for getAllGroupAnnouncements mandatory
2016-01-16 18:39:04 +00:00
Shaun Barratt
ac02f6cb49 Added getAllAnnouncements
Added example on how to use it
2016-01-16 00:06:42 +00:00
Shaun Barratt
d84601e256 Adding the whitespace back (blame atom.io!)
Converting spaces to tabs.
2016-01-15 21:28:43 +00:00
Shaun Barratt
4152865f5e Adding ability to edit an annoucement.
Added an example.
2016-01-15 17:48:57 +00:00
Alexander Corn
7627e6a3a0 3.17.2 2016-01-13 01:02:52 -05:00
Alexander Corn
bbcf0eb72f Merge pull request #65 from spddl/master
Error: You must fill out all fields in at least one language - fix
2016-01-13 01:01:58 -05:00
spddl
d51b6582e2 Error: You must fill out all fields in at least one language fix 2016-01-13 06:16:51 +01:00
Alexander Corn
bbd339b88b 3.17.1 2016-01-05 22:46:05 -05:00
Alexander Corn
fcaaa38085 Merge pull request #59 from Aareksio/master
Fixed chatMessage function
2016-01-05 22:44:54 -05:00
Mole
6d8d0c5fbb Fixed missing 'var self = this;' 2016-01-05 15:33:54 +01:00
Alexander Corn
08c9ab6809 3.17.0 2016-01-04 19:17:46 -05:00
Alexander Corn
c150425ee5 Use gzip for HTTP requests 2016-01-03 14:38:02 -05:00
Alexander Corn
5c2666e0f4 Merge pull request #55 from Mikxail/constructor-additional-options
additional options for SteamCommunity constructor
2015-12-28 00:24:11 -05:00
Alexander Corn
c64b6c7e99 Merge pull request #53 from Mikxail/bugfix-market-search
bugfix call performSearch
2015-12-28 00:17:26 -05:00
Mikhail Konovalov
318f9ab2b4 bugfix call performSearch 2015-12-27 16:53:15 +03:00
Mikhail Konovalov
3167034b97 additional options for SteamCommunity constructor 2015-12-27 16:08:06 +03:00
Alexander Corn
3bfe8c3713 3.16.0 2015-12-26 18:38:53 -05:00
Alexander Corn
0c4e026701 Require steamguard value in oAuthLogin method 2015-12-26 18:34:22 -05:00
Alexander Corn
c246011fe2 Added oauth token to login callback 2015-12-26 18:34:11 -05:00
Alexander Corn
c290e16dc5 Generate sessionids that follow the same pattern as Valve's 2015-12-26 18:19:35 -05:00
Alexander Corn
f8852ba6c4 Pretend to be Chrome 2015-12-26 18:17:01 -05:00
Alexander Corn
52ee65d9da Added oAuthLogin 2015-12-26 18:15:09 -05:00
Alexander Corn
42e04b123a 3.15.0 2015-12-21 14:22:27 -05:00
Alexander Corn
1f69d1fc04 CEconItem: is_currency is bool, fraudwarnings/descriptions are arrays 2015-12-21 14:22:07 -05:00
Alexander Corn
e4b5e763eb Added support for escrow to getInventoryHistory 2015-12-21 14:21:47 -05:00
Alexander Corn
6feb607366 3.14.1593 2015-12-15 00:29:44 -05:00
Alexander Corn
cc64d9883a Fixed some errors not being Error objects 2015-12-15 00:29:00 -05:00
Alexander Corn
d4a92b4dea Added enable_twofactor example 2015-12-12 18:41:10 -05:00
Alexander Corn
e2849719c1 3.14.159 2015-12-10 18:43:32 -05:00
Alexander Corn
c9541d093c Delete mobile-client cookies after we login so we don't get mobile pages 2015-12-10 18:42:16 -05:00
Alexander Corn
339d5dc1e4 3.14.1 2015-12-07 16:36:20 -05:00
Alexander Corn
2a7a03d35e Use SHA-1 hash of our SteamID when enabling 2FA 2015-12-07 16:34:49 -05:00
Alexander Corn
ff1c3279c8 Use random hex value instead of current time for deviceid 2015-12-07 11:42:10 -05:00
Alexander Corn
9175a44828 3.14.0 2015-12-05 01:41:39 -05:00
Alexander Corn
deeeb633cf Delete _identitySecret if we have it when we stop polling 2015-12-05 01:41:35 -05:00
Alexander Corn
a50bd35a54 Added proper queue for confirmations 2015-12-05 01:37:41 -05:00
Alexander Corn
5bf51a2e3e Added automatic confirmation accepting 2015-12-05 00:41:27 -05:00
Alexander Corn
448b32b9c6 callback with an error if we don't get a valid RSA key (resolves #29) 2015-12-05 00:24:52 -05:00
Alexander Corn
01428e6007 3.13.0 2015-12-03 14:03:59 -05:00
Alexander Corn
43d1147fd7 Add tradeConfirmation alias for emailConfirmation and marketConfirmation
Resolves #24
2015-12-03 13:59:54 -05:00
Alexander Corn
479cc47bf5 Fixed crashes on 2FA errors (fixes #22) 2015-12-03 13:57:49 -05:00
13 changed files with 510 additions and 39 deletions

View File

@@ -25,11 +25,18 @@ function CEconItem(item, descriptions, contextID) {
}
}
this.is_currency = !!this.is_currency;
this.tradable = !!this.tradable;
this.marketable = !!this.marketable;
this.commodity = !!this.commodity;
this.market_tradable_restriction = (this.market_tradable_restriction ? parseInt(this.market_tradable_restriction, 10) : 0);
this.market_marketable_restriction = (this.market_marketable_restriction ? parseInt(this.market_marketable_restriction, 10) : 0);
this.fraudwarnings = this.fraudwarnings || [];
this.descriptions = this.descriptions || [];
if(this.owner && JSON.stringify(this.owner) == '{}') {
this.owner = null;
}
}
CEconItem.prototype.getImageURL = function() {

View File

@@ -69,7 +69,7 @@ function performSearch(request, qs, results, callback) {
callback(null, results);
} else {
qs.start += body.pagesize;
performSearch(request, qs, results, callback);
performSearch.call(self, request, qs, results, callback);
}
});
}

View File

@@ -64,7 +64,7 @@ CSteamGroup.prototype.getMembers = function(addresses, callback) {
callback = addresses;
addresses = null;
}
this._community.getGroupMembers(this.steamID, callback, null, null, addresses, 0);
};
@@ -76,10 +76,22 @@ CSteamGroup.prototype.leave = function(callback) {
this._community.leaveGroup(this.steamID, callback);
};
CSteamGroup.prototype.getAllAnnouncements = function(time, callback) {
this._community.getAllGroupAnnouncements(this.steamID, time, callback);
};
CSteamGroup.prototype.postAnnouncement = function(headline, content, callback) {
this._community.postGroupAnnouncement(this.steamID, headline, content, callback);
};
CSteamGroup.prototype.editAnnouncement = function(annoucementID, headline, content, callback) {
this._community.editGroupAnnouncement(this.steamID, annoucementID, headline, content, callback)
};
CSteamGroup.prototype.deleteAnnouncement = function(annoucementID, callback) {
this._community.deleteGroupAnnouncement(this.steamID, annoucementID, callback)
};
CSteamGroup.prototype.scheduleEvent = function(name, type, description, time, server, callback) {
this._community.scheduleGroupEvent(this.steamID, name, type, description, time, server, callback);
};

View File

@@ -101,7 +101,8 @@ SteamCommunity.prototype.chatMessage = function(recipient, text, type, callback)
}
type = type || 'saytext';
var self = this;
this.request.post({
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Message/v1",
"form": {

View File

@@ -1,5 +1,7 @@
var SteamCommunity = require('../index.js');
var Cheerio = require('cheerio');
var SteamTotp = require('steam-totp');
var Async = require('async');
var CConfirmation = require('../classes/CConfirmation.js');
@@ -15,6 +17,7 @@ SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
request(this, "conf", key, time, "conf", null, false, function(err, body) {
if(err) {
callback(err);
return;
}
var $ = Cheerio.load(body);
@@ -73,6 +76,7 @@ SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, ca
request(this, "details/" + confID, key, time, "details", null, true, function(err, body) {
if(err) {
callback(err);
return;
}
if(!body.success) {
@@ -137,7 +141,7 @@ SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time,
function request(community, url, key, time, tag, params, json, callback) {
params = params || {};
params.p = "android:" + Date.now();
params.p = SteamTotp.getDeviceID(community.steamID);
params.a = community.steamID.getSteamID64();
params.k = key;
params.t = time;
@@ -162,11 +166,13 @@ function request(community, url, key, time, tag, params, json, callback) {
/**
* Start automatically polling our confirmations for new ones. The `confKeyNeeded` event will be emitted when we need a confirmation key, or `newConfirmation` when we get a new confirmation
* @param {int} pollInterval - The interval, in milliseconds, at which we will poll for confirmations. This shouldn't be any less than 10,000 probably.
* @param {Buffer|string|null} [identitySecret=null] - Your identity_secret. If passed, all confirmations will be automatically accepted and nothing will be emitted.
*/
SteamCommunity.prototype.startConfirmationChecker = function(pollInterval) {
SteamCommunity.prototype.startConfirmationChecker = function(pollInterval, identitySecret) {
this._confirmationPollInterval = pollInterval;
this._knownConfirmations = this._knownConfirmations || {};
this._confirmationKeys = this._confirmationKeys || {};
this._identitySecret = identitySecret;
if(this._confirmationTimer) {
clearTimeout(this._confirmationTimer);
@@ -183,6 +189,10 @@ SteamCommunity.prototype.stopConfirmationChecker = function() {
delete this._confirmationPollInterval;
}
if(this._identitySecret) {
delete this._identitySecret;
}
if(this._confirmationTimer) {
clearTimeout(this._confirmationTimer);
delete this._confirmationTimer;
@@ -200,6 +210,27 @@ SteamCommunity.prototype.checkConfirmations = function() {
}
var self = this;
if(!this._confirmationQueue) {
this._confirmationQueue = Async.queue(function(conf, callback) {
// Worker to process new confirmations
if(self._identitySecret) {
// We should accept this
self.emit('debug', "Accepting confirmation #" + conf.id);
var time = Math.floor(Date.now() / 1000);
conf.respond(time, SteamTotp.getConfirmationKey(self._identitySecret, time, "allow"), true, function() {
// If there was an error and it wasn't actually accepted, we'll pick it up again
delete self._knownConfirmations[conf.id];
setTimeout(callback, 1000); // Call the callback in 1 second, to make sure the time changes
});
} else {
self.emit('newConfirmation', conf);
setTimeout(callback, 1000); // Call the callback in 1 second, to make sure the time changes
}
}, 1);
}
this.emit('debug', 'Checking confirmations');
this._confirmationCheckerGetKey('conf', function(err, key) {
if(err) {
resetTimer();
@@ -225,16 +256,16 @@ SteamCommunity.prototype.checkConfirmations = function() {
// We have new confirmations! Grab a key to get details.
self._confirmationCheckerGetKey('details', function(err, key) {
var handled = 0;
newOnes.forEach(function(conf) {
self._knownConfirmations[conf.id] = conf; // Add it to our list of known confirmations
if(err) {
handleNewConfirmation(conf, handled++);
self._confirmationQueue.push(conf);
} else {
// Get its offer ID, if we can
conf.getOfferID(key.time, key.key, function(err, offerID) {
conf.offerID = offerID ? offerID : null;
handleNewConfirmation(conf, handled++);
self._confirmationQueue.push(conf);
});
}
});
@@ -255,12 +286,32 @@ SteamCommunity.prototype.checkConfirmations = function() {
// Delay them by 1 second per new confirmation that we see, so that keys won't be the same.
setTimeout(function() {
self.emit('newConfirmation', conf);
if(self._identitySecret) {
self.emit('debug', 'Accepting confirmation ' + conf.id);
var time = Math.floor(Date.now() / 1000);
conf.respond(time, SteamTotp.getConfirmationKey(self._identitySecret, time, "allow"), true, function() {
delete self._knownConfirmations[conf.id];
});
} else {
self.emit('newConfirmation', conf);
}
}, handleNumber * 1000);
}
};
SteamCommunity.prototype._confirmationCheckerGetKey = function(tag, callback) {
if(this._identitySecret) {
if(tag == 'details') {
// We don't care about details
callback(new Error("Disabled"));
return;
}
var time = Math.floor(Date.now() / 1000);
callback(null, {"time": time, "key": SteamTotp.getConfirmationKey(this._identitySecret, time, tag)});
return;
}
var existing = this._confirmationKeys[tag];
var reusable = ['conf', 'details'];

View File

@@ -125,6 +125,56 @@ SteamCommunity.prototype.leaveGroup = function(gid, callback) {
});
};
SteamCommunity.prototype.getAllGroupAnnouncements = function(gid, time, callback) {
if(typeof gid === 'string') {
gid = new SteamID(gid);
}
if(typeof time === 'function') {
callback = time;
time = new Date(0); // The beginnig of time...
}
var self = this;
this.request({
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/rss/"
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
xml2js.parseString(body, function(err, results) {
if(err) {
return callback(err);
}
if(!results.rss.channel[0].item) {
return callback(null, []);
}
var announcements = results.rss.channel[0].item.map(function(announcement) {
var splitLink = announcement.link[0].split('/');
return {
headline: announcement.title[0],
content: announcement.description[0],
date: new Date(announcement.pubDate[0]),
author: announcement.author[0],
aid: splitLink[splitLink.length - 1]
}
}).filter(function(announcement) {
return (announcement.date > time);
});
return callback(null, announcements);
});
});
}
SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content, callback) {
if(typeof gid === 'string') {
gid = new SteamID(gid);
@@ -137,15 +187,82 @@ SteamCommunity.prototype.postGroupAnnouncement = function(gid, headline, content
"sessionID": this.getSessionID(),
"action": "post",
"headline": headline,
"body": content
"body": content,
"languages[0][headline]": headline,
"languages[0][body]": content
}
}, function(err, response, body) {
if(!callback) {
return;
}
if(err || response.statusCode >= 400) {
callback(err || new Error("HTTP error " + response.statusCode));
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
callback(null);
})
};
SteamCommunity.prototype.editGroupAnnouncement = function(gid, aid, headline, content, callback) {
if(typeof gid === 'string') {
gid = new SteamID(gid);
}
var self = this;
var submitData = {
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements",
"form": {
"sessionID": this.getSessionID(),
"gid": aid,
"action": "update",
"headline": headline,
"body": content,
"languages[0][headline]": headline,
"languages[0][body]": content,
"languages[0][updated]": 1
}
}
this.request.post(submitData, function(err, response, body) {
if(!callback) {
return;
}
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
callback(null);
})
};
SteamCommunity.prototype.deleteGroupAnnouncement = function(gid, aid, callback) {
if(typeof gid === 'string') {
gid = new SteamID(gid);
}
var self = this;
var submitData = {
"uri": "https://steamcommunity.com/gid/" + gid.getSteamID64() + "/announcements/delete/" + aid + "?sessionID=" + this.getSessionID(),
}
this.request.get(submitData, function(err, response, body) {
if(!callback) {
return;
}
if(self._checkHttpError(err, response, callback)) {
return;
}

View File

@@ -50,6 +50,8 @@ SteamCommunity.prototype.getInventoryHistory = function(options, callback) {
for(var i = 0; i < trades.length; i++) {
item = $(trades[i]);
trade = {};
trade.onHold = !!item.find('span:nth-of-type(2)').text().match(/Trade on Hold/i);
timeMatch = item.find('.tradehistory_timestamp').html().match(/(\d+):(\d+)(am|pm)/);
if(timeMatch[1] == 12 && timeMatch[3] == 'am') {
@@ -81,7 +83,7 @@ SteamCommunity.prototype.getInventoryHistory = function(options, callback) {
items = item.find('.history_item');
for(j = 0; j < items.length; j++) {
match = body.match(new RegExp("HistoryPageCreateItemHover\\( '" + $(items[j]).attr('id') + "', (\\d+), '(\\d+)', '(\\d+)', '(\\d+)' \\);"));
match = body.match(new RegExp("HistoryPageCreateItemHover\\( '" + $(items[j]).attr('id') + "', (\\d+), '(\\d+)', '(\\d+|class_\\d+_instance_\\d+|class_\\d+)', '(\\d+)' \\);"));
econItem = historyInventory[match[1]][match[2]][match[3]];
if($(items[j]).attr('id').indexOf('received') != -1) {

View File

@@ -191,9 +191,14 @@ SteamCommunity.prototype.profileSettings = function(settings, callback) {
values.inventoryGiftPrivacy = settings[i] ? 1 : 0;
break;
case 'emailConfirmation':
case 'emailConfirmation': // deprecated
case 'tradeConfirmation':
values.tradeConfirmationSetting = settings[i] ? 1 : 0;
break;
case 'marketConfirmation':
values.marketConfirmationSetting = settings[i] ? 1 : 0;
break;
}
}

View File

@@ -18,7 +18,7 @@ SteamCommunity.prototype.enableTwoFactor = function(callback) {
// Create a random device ID hash
var hash = require('crypto').createHash('sha1');
hash.update(Math.random().toString());
hash.update(self.steamID.getSteamID64());
hash = hash.digest('hex');
self.request.post({

View File

@@ -0,0 +1,109 @@
var SteamCommunity = require('../index.js');
var ReadLine = require('readline');
var fs = require('fs');
var community = new SteamCommunity();
var rl = ReadLine.createInterface({
"input": process.stdin,
"output": process.stdout
});
rl.question("Username: ", function(accountName) {
rl.question("Password: ", function(password) {
doLogin(accountName, password);
});
});
function doLogin(accountName, password, authCode, twoFactorCode) {
community.login({
"accountName": accountName,
"password": password,
"authCode": authCode,
"twoFactorCode": twoFactorCode
}, function(err, sessionID, cookies, steamguard) {
if(err) {
if(err.message == 'SteamGuardMobile') {
rl.question("Steam Authenticator Code: ", function(code) {
doLogin(accountName, password, null, code);
});
return;
}
if(err.message == 'SteamGuard') {
console.log("An email has been sent to your address at " + err.emaildomain);
rl.question("Steam Guard Code: ", function(code) {
doLogin(accountName, password, code);
});
return;
}
console.log(err);
process.exit();
return;
}
console.log("Logged on!");
rl.question("Group ID: ", function(gid) {
community.getSteamGroup(gid, function(err, group) {
if (err) {
console.log(err);
process.exit(1);
}
group.getAllAnnouncements(function(err, announcements) {
if(announcements.length === 0) {
return console.log("This group has no announcements");
}
for (var i = announcements.length - 1; i >= 0; i--) {
console.log("[%s] %s %s: %s", announcements[i].date, announcements[i].aid, announcements[i].author, announcements[i].content);
};
rl.question("Would you like to delete delete or edit an annoucement? (Type edit/delete): ", function(choice) {
rl.question("Annoucement ID: ", function(aid) {
if(choice === 'edit') {
rl.question("New title: ", function(header) {
rl.question("New body: ", function(content) {
// EW THE PYRAMID!
// Try replace this with delete!
editAnnouncement(group, aid, header, content);
});
});
} else {
deleteAnnouncement(group, aid);
}
});
});
});
});
});
});
}
function editAnnouncement(group, aid, header, content) {
// Actual community method.
group.editAnnouncement(aid, header, content, function(error) {
if(!error) {
console.log("Annoucement edited!");
} else {
console.log("Unable to edit annoucement! %j", error);
process.exit(1);
}
});
}
function deleteAnnouncement(group, aid) {
// group.deleteAnnouncement(aid);
// Or
group.deleteAnnouncement(aid, function(err) {
if(!err) {
console.log("Deleted");
} else {
console.log("Error deleting announcement.");
}
})
}

View File

@@ -0,0 +1,97 @@
var SteamCommunity = require('../index.js');
var ReadLine = require('readline');
var fs = require('fs');
var community = new SteamCommunity();
var rl = ReadLine.createInterface({
"input": process.stdin,
"output": process.stdout
});
rl.question("Username: ", function(accountName) {
rl.question("Password: ", function(password) {
doLogin(accountName, password);
});
});
function doLogin(accountName, password, authCode) {
community.login({
"accountName": accountName,
"password": password,
"authCode": authCode
}, function(err, sessionID, cookies, steamguard) {
if(err) {
if(err.message == 'SteamGuardMobile') {
console.log("This account already has two-factor authentication enabled.");
process.exit();
return;
}
if(err.message == 'SteamGuard') {
console.log("An email has been sent to your address at " + err.emaildomain);
rl.question("Steam Guard Code: ", function(code) {
doLogin(accountName, password, code);
});
return;
}
console.log(err);
process.exit();
return;
}
console.log("Logged on!");
community.enableTwoFactor(function(err, response) {
if(err) {
if(err.eresult == 2) {
console.log("Error: Failed to enable two-factor authentication. Do you have a phone number attached to your account?");
process.exit();
return;
}
if(err.eresult == 84) {
console.log("Error: RateLimitExceeded. Try again later.");
process.exit();
return;
}
console.log(err);
process.exit();
return;
}
if(response.status != 1) {
console.log("Error: Status " + response.status);
process.exit();
return;
}
console.log("Writing secrets to twofactor_" + community.steamID.getSteamID64() + ".json");
console.log("Revocation code: " + response.revocation_code);
fs.writeFile("twofactor_" + community.steamID.getSteamID64() + ".json", JSON.stringify(response, null, "\t"));
promptActivationCode(response);
});
});
}
function promptActivationCode(response) {
rl.question("SMS Code: ", function(smsCode) {
community.finalizeTwoFactor(response.shared_secret, smsCode, function(err) {
if(err) {
if(err.message == "Invalid activation code") {
console.log(err);
promptActivationCode(response);
return;
}
console.log(err);
} else {
console.log("Two-factor authentication enabled!");
}
process.exit();
});
});
}

100
index.js
View File

@@ -3,36 +3,49 @@ var RSA = require('node-bignumber').Key;
var hex2b64 = require('node-bignumber').hex2b64;
var SteamID = require('steamid');
const USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36";
require('util').inherits(SteamCommunity, require('events').EventEmitter);
module.exports = SteamCommunity;
SteamCommunity.SteamID = SteamID;
function SteamCommunity(localAddress) {
function SteamCommunity(options) {
options = options || {};
this._jar = Request.jar();
this._captchaGid = -1;
this.chatState = SteamCommunity.ChatState.Offline;
var defaults = {
"jar": this._jar,
"timeout": 50000
"timeout": options.timeout || 50000,
"gzip": true,
"headers": {
"User-Agent": options.userAgent || USER_AGENT
}
};
if(localAddress) {
defaults.localAddress = localAddress;
if (typeof options == "string") {
options = {
localAddress: options
};
}
this._options = options;
if (options.localAddress) {
defaults.localAddress = options.localAddress;
}
this.request = Request.defaults(defaults);
this.request = options.request || Request.defaults();
this.request = this.request.defaults(defaults);
// English
this._jar.setCookie(Request.cookie('Steam_Language=english'), 'https://steamcommunity.com');
// UTC
this._jar.setCookie(Request.cookie('timezoneOffset=0,0'), 'https://steamcommunity.com');
this._jar.setCookie(Request.cookie("mobileClientVersion=0 (2.1.3)"), "https://steamcommunity.com");
this._jar.setCookie(Request.cookie("mobileClient=android"), "https://steamcommunity.com");
}
SteamCommunity.prototype.login = function(details, callback) {
@@ -46,10 +59,13 @@ SteamCommunity.prototype.login = function(details, callback) {
// headers required to convince steam that we're logging in from a mobile device so that we can get the oAuth data
var mobileHeaders = {
"X-Requested-With": "com.valvesoftware.android.steam.community",
"referer": "https://steamcommunity.com/mobilelogin?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client",
"user-agent": "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
"accept": "text/javascript, text/html, application/xml, text/xml, */*"
"Referer": "https://steamcommunity.com/mobilelogin?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client",
"User-Agent": "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
"Accept": "text/javascript, text/html, application/xml, text/xml, */*"
};
this._jar.setCookie(Request.cookie("mobileClientVersion=0 (2.1.3)"), "https://steamcommunity.com");
this._jar.setCookie(Request.cookie("mobileClient=android"), "https://steamcommunity.com");
this.request.post("https://steamcommunity.com/login/getrsakey/", {
"form": {
@@ -57,7 +73,9 @@ SteamCommunity.prototype.login = function(details, callback) {
},
"headers": mobileHeaders
}, function(err, response, body) {
// Remove the mobile cookies
if(err) {
deleteMobileCookies();
callback(err);
return;
}
@@ -66,9 +84,16 @@ SteamCommunity.prototype.login = function(details, callback) {
try {
json = JSON.parse(body);
} catch(e) {
deleteMobileCookies();
callback(e);
return;
}
if(!json.publickey_mod || !json.publickey_exp) {
deleteMobileCookies();
callback(new Error("Invalid RSA key received"));
return;
}
var key = new RSA();
key.setPublic(json.publickey_mod, json.publickey_exp);
@@ -94,6 +119,8 @@ SteamCommunity.prototype.login = function(details, callback) {
"form": form,
"headers": mobileHeaders
}, function(err, response, body) {
deleteMobileCookies();
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -138,10 +165,53 @@ SteamCommunity.prototype.login = function(details, callback) {
}
}
callback(null, sessionID, cookies, steamguard);
callback(null, sessionID, cookies, steamguard, oAuth.oauth_token);
}
});
});
function deleteMobileCookies() {
var cookie = Request.cookie('mobileClientVersion=');
cookie.expires = new Date(0);
self._jar.setCookie(cookie, "https://steamcommunity.com");
cookie = Request.cookie('mobileClient=');
cookie.expires = new Date(0);
self._jar.setCookie(cookie, "https://steamcommunity.com");
}
};
SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) {
steamguard = steamguard.split('||');
var steamID = new SteamID(steamguard[0]);
var self = this;
this.request.post({
"uri": "https://api.steampowered.com/IMobileAuthService/GetWGToken/v1/",
"form": {
"access_token": token
},
"json": true
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(!body.response || !body.response.token || !body.response.token_secure) {
callback(new Error("Malformed response"));
return;
}
var cookies = [
'steamLogin=' + encodeURIComponent(steamID.getSteamID64() + '||' + body.response.token),
'steamLoginSecure=' + encodeURIComponent(steamID.getSteamID64() + '||' + body.response.token_secure),
'steamMachineAuth' + steamID.getSteamID64() + '=' + steamguard[1],
'sessionid=' + self.getSessionID()
];
self.setCookies(cookies);
callback(null, self.getSessionID(), cookies);
});
};
SteamCommunity.prototype.setCookies = function(cookies) {
@@ -171,7 +241,7 @@ SteamCommunity.prototype.getSessionID = function() {
};
function generateSessionID() {
return Math.floor(Math.random() * 1000000000);
return require('crypto').randomBytes(12).toString('hex');
}
SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
@@ -288,7 +358,7 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
var match = response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/);
if(!match) {
callback("Can't get profile URL");
callback(new Error("Can't get profile URL"));
return;
}

View File

@@ -1,6 +1,6 @@
{
"name": "steamcommunity",
"version": "3.12.2",
"version": "3.18.2",
"description": "Provides an interface for logging into and interacting with the Steam Community website",
"keywords": ["steam", "steam community"],
"homepage": "https://github.com/DoctorMcKay/node-steamcommunity",
@@ -13,12 +13,12 @@
"url": "https://github.com/DoctorMcKay/node-steamcommunity.git"
},
"dependencies": {
"request": "^2.61.0",
"node-bignumber": "^1.2.1",
"steamid": "^0.3.1",
"xml2js": "^0.4.11",
"cheerio": "^0.19.0",
"async": "^1.4.2",
"steam-totp": "^1.0.0"
"request": "^2.61.0",
"node-bignumber": "^1.2.1",
"steamid": "^0.3.1",
"xml2js": "^0.4.11",
"cheerio": "^0.19.0",
"async": "^1.4.2",
"steam-totp": "^1.3.0"
}
}