Compare commits

...

67 Commits

Author SHA1 Message Date
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
Alexander Corn
01217a3659 3.12.2 2015-12-02 22:38:59 -05:00
Alexander Corn
0e34bceb1f Only reset the polling timer if we have an interval set 2015-12-02 22:38:51 -05:00
Alexander Corn
c4ea8eeb41 3.12.1
I screwed up 3.12.0 and npm won't let me publish over it, so 3.12.0 just
doesn't exist.
2015-12-02 22:25:00 -05:00
Alexander Corn
0f83fe8c64 Added confirmation polling 2015-12-02 22:20:16 -05:00
Alexander Corn
5624611421 Moved getWebApiKey to webapi.js component 2015-12-02 21:35:35 -05:00
Alexander Corn
49d2bb4252 Fixed finalizeTwoFactor checking success before want_more (fixes #16) 2015-12-02 21:33:33 -05:00
Alexander Corn
b54ccff7c8 Added confirmations 2015-12-02 21:31:17 -05:00
Alexander Corn
b82f7ca045 Merge pull request #17 from s992/master
Updates login code to use mobile login headers and cookies
2015-12-02 19:19:50 -05:00
Sean Walsh
2526539266 removes extra loginfriendlyname 2015-12-01 21:41:30 -08:00
Sean Walsh
fc75036974 moves headers away from being default on everything. only use them on login. 2015-12-01 17:57:26 -08:00
Sean Walsh
ee1e819812 removes extra steam_language cookie 2015-12-01 17:40:51 -08:00
Sean Walsh
fceea0737d updates login code to use mobile login so that we can grab the oauth token. 2015-11-30 17:39:55 -08:00
Alexander Corn
f3ac556922 Added check for community error when getting webapi oauth token 2015-11-30 19:40:10 -05:00
Alexander Corn
2e02c14455 3.11.1 2015-11-27 22:09:47 -05:00
Alexander Corn
8f580fc231 Fixed enableTwoFactor returning success when it wasn't successful 2015-11-27 22:09:36 -05:00
Alexander Corn
6f596b5b16 3.11.0 2015-11-27 17:57:57 -05:00
Alexander Corn
1249e28d83 Added enableTwoFactor and finalizeTwoFactor methods 2015-11-27 17:57:39 -05:00
Alexander Corn
85bcaa70be 3.10.0 2015-11-27 01:46:10 -05:00
Alexander Corn
2a5419513c Added disableTwoFactor method 2015-11-27 01:45:58 -05:00
Alexander Corn
deec5c52a4 Fixed isLimitedAccount and vacBanned (fixes #12) 2015-11-27 01:32:12 -05:00
Alexander Corn
2399a5b783 Added getWebApiOauthToken 2015-11-27 01:28:31 -05:00
Alexander Corn
efea8c6265 3.9.10 2015-11-11 00:52:18 -05:00
Alexander Corn
2be414b20c Merge pull request #10 from charredgrass/master
Fixed error on getNotifications
2015-11-11 00:36:54 -05:00
Maxwell Chow
25ebb4c5a3 Fixed error on getNotifications 2015-11-10 20:46:17 -08:00
Alexander Corn
ac87fd3a40 3.9.9 2015-11-09 23:30:39 -05:00
Alexander Corn
c67e2e04f1 Merge pull request #9 from shaunidiot/patch-1
Spelling error
2015-11-09 23:30:02 -05:00
Shaun
83eeb0f190 Spelling error 2015-11-10 12:29:23 +08:00
Alexander Corn
e09cf24fbf 3.9.8 2015-10-26 21:30:46 -04:00
Alexander Corn
9d2b5ade67 Fixed scheduleGroupEvent method
Fixes #7
2015-10-26 21:30:27 -04:00
Alexander Corn
be4e5c9449 3.9.7 2015-10-14 00:37:36 -04:00
Alexander Corn
5926197f23 Fixed primary group setting not working 2015-10-14 00:37:27 -04:00
Alexander Corn
2d86f81142 3.9.6 2015-10-06 18:53:33 -04:00
Alexander Corn
f37bff4a57 Make the error in getWebApiKey an Error object 2015-10-06 18:53:25 -04:00
Alexander Corn
c700b7663b 3.9.5 2015-10-04 19:47:06 -04:00
Alexander Corn
c26e548c64 Fixed some dumb code 2015-10-04 19:46:38 -04:00
Alexander Corn
658d8fb708 Merge pull request #6 from JorisD33/patch-get-inventory
Patch getInventory
2015-10-04 19:43:59 -04:00
Joris
cd68841d1d Fix getInventory issue 2015-10-04 23:28:40 +02:00
Joris
5853968661 Fix CSteamUser constructor 2015-10-04 23:20:30 +02:00
Alexander Corn
10d899f7a7 3.9.4 2015-09-20 00:49:51 -04:00
Alexander Corn
4e1453e702 Better handling for missing items in user XML 2015-09-20 00:49:42 -04:00
Alexander Corn
f3cf2a4361 3.9.3 2015-09-20 00:33:32 -04:00
Alexander Corn
2890b70add Actually fixed the previous issue 2015-09-20 00:33:24 -04:00
14 changed files with 841 additions and 86 deletions

20
classes/CConfirmation.js Normal file
View File

@@ -0,0 +1,20 @@
module.exports = CConfirmation;
function CConfirmation(community, data) {
this._community = community;
this.id = data.id;
this.key = data.key;
this.title = data.title;
this.receiving = data.receiving;
this.time = data.time;
this.icon = data.icon;
}
CConfirmation.prototype.getOfferID = function(time, key, callback) {
this._community.getConfirmationOfferID(this.id, time, key, callback);
};
CConfirmation.prototype.respond = function(time, key, accept, callback) {
this._community.respondToConfirmation(this.id, this.key, time, key, accept, callback);
};

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

@@ -41,8 +41,9 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) {
}
}
if(!result.profile.steamID64 || !result.profile.onlineState) {
if(!result.profile.steamID64) {
callback(new Error("No valid response"));
return;
}
callback(null, new CSteamUser(self, result.profile, customurl));
@@ -54,22 +55,26 @@ function CSteamUser(community, userData, customurl) {
this._community = community;
this.steamID = new SteamID(userData.steamID64[0]);
this.name = userData.steamID[0];
this.onlineState = userData.onlineState[0];
this.stateMessage = userData.stateMessage[0];
this.privacyState = userData.privacyState[0];
this.visibilityState = userData.visibilityState[0];
this.avatarHash = userData.avatarIcon[0].match(/([0-9a-f]+)\.[a-z]+$/)[1];
this.vacBanned = !!userData.vacBanned[0];
this.tradeBanState = userData.tradeBanState[0];
this.isLimitedAccount = !!userData.isLimitedAccount[0];
this.customURL = userData.customURL ? userData.customURL[0] : customurl;
this.name = processItem('steamID');
this.onlineState = processItem('onlineState');
this.stateMessage = processItem('stateMessage');
this.privacyState = processItem('privacyState', 'uncreated');
this.visibilityState = processItem('visibilityState');
this.avatarHash = processItem('avatarIcon', '').match(/([0-9a-f]+)\.[a-z]+$/);
if(this.avatarHash) {
this.avatarHash = this.avatarHash[1];
}
this.vacBanned = processItem('vacBanned', false) == 1;
this.tradeBanState = processItem('tradeBanState', 'None');
this.isLimitedAccount = processItem('isLimitedAccount') == 1;
this.customURL = processItem('customURL', customurl);
if(this.visibilityState == 3) {
this.memberSince = new Date(userData.memberSince[0].replace(/(\d{1,2})(st|nd|th)/, "$1"));
this.location = userData.location[0] || null;
this.realName = userData.realname[0] || null;
this.summary = userData.summary[0] || null;
this.memberSince = new Date(processItem('memberSince', '0').replace(/(\d{1,2})(st|nd|th)/, "$1"));
this.location = processItem('location');
this.realName = processItem('realname');
this.summary = processItem('summary');
} else {
this.memberSince = null;
this.location = null;
@@ -92,6 +97,14 @@ function CSteamUser(community, userData, customurl) {
return new SteamID(group.groupID64[0]);
});
}
function processItem(name, defaultVal) {
if(!userData[name]) {
return defaultVal;
}
return userData[name][0];
}
}
CSteamUser.getAvatarURL = function(hash, size, protocol) {
@@ -144,5 +157,5 @@ CSteamUser.prototype.getInventoryContexts = function(callback) {
};
CSteamUser.prototype.getInventory = function(appID, contextID, tradableOnly, callback) {
this._community.getInventory(appID, contextID, tradableOnly, callback);
this._community.getUserInventory(this.steamID, appID, contextID, tradableOnly, callback);
};

View File

@@ -40,17 +40,9 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
this.chatState = SteamCommunity.ChatState.LoggingOn;
var self = this;
this.request("https://steamcommunity.com/chat", function(err, response, body) {
if(err || response.statusCode != 200) {
self.emit('debug', 'Error requesting chat WebAPI token: ' + (err ? err.message : "HTTP error " + response.statusCode));
self.chatState = SteamCommunity.ChatState.LogOnFailed;
setTimeout(self.chatLogon.bind(self), 5000);
return;
}
var match = body.match(/[0-9a-f]{32}/);
if(!match) {
self.emit('debug', 'Couldn\'t find a WebAPI chat token in the response.');
this.getWebApiOauthToken(function(err, token) {
if(err) {
self.emit('debug', "Cannot get oauth token: " + err.message);
self.chatState = SteamCommunity.ChatState.LogOnFailed;
setTimeout(self.chatLogon.bind(self), 5000);
return;
@@ -60,7 +52,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Logon/v1",
"form": {
"ui_mode": uiMode,
"access_token": match[0]
"access_token": token
},
"json": true
}, function(err, response, body) {
@@ -81,7 +73,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
self._chat = {
"umqid": body.umqid,
"message": body.message,
"accessToken": match[0],
"accessToken": token,
"interval": interval
};

335
components/confirmations.js Normal file
View File

@@ -0,0 +1,335 @@
var SteamCommunity = require('../index.js');
var Cheerio = require('cheerio');
var SteamTotp = require('steam-totp');
var Async = require('async');
var CConfirmation = require('../classes/CConfirmation.js');
/**
* Get a list of your account's currently outstanding confirmations.
* @param {int} time - The unix timestamp with which the following key was generated
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "conf" (this key can be reused)
* @param {SteamCommunity~getConfirmations} callback - Called when the list of confirmations is received
*/
SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
var self = this;
request(this, "conf", key, time, "conf", null, false, function(err, body) {
if(err) {
callback(err);
return;
}
var $ = Cheerio.load(body);
var empty = $('#mobileconf_empty');
if(empty.length > 0) {
if(!$(empty).hasClass('mobileconf_done')) {
// An error occurred
callback(new Error(empty.find('div:nth-of-type(2)').text()));
} else {
callback(null, []);
}
return;
}
// We have something to confirm
var confirmations = $('#mobileconf_list');
if(!confirmations) {
callback(new Error("Malformed response"));
return;
}
var confs = [];
Array.prototype.forEach.call(confirmations.find('.mobileconf_list_entry'), function(conf) {
conf = $(conf);
var img = conf.find('.mobileconf_list_entry_icon img');
confs.push(new CConfirmation(self, {
"id": conf.data('confid'),
"key": conf.data('key'),
"title": conf.find('.mobileconf_list_entry_description>div:nth-of-type(1)').text().trim(),
"receiving": conf.find('.mobileconf_list_entry_description>div:nth-of-type(2)').text().trim(),
"time": conf.find('.mobileconf_list_entry_description>div:nth-of-type(3)').text().trim(),
"icon": img.length < 1 ? '' : $(img).attr('src')
}));
});
callback(null, confs);
});
};
/**
* @callback SteamCommunity~getConfirmations
* @param {Error|null} err - An Error object on failure, or null on success
* @param {CConfirmation[]} confirmations - An array of CConfirmation objects
*/
/**
* Get the trade offer ID associated with a particular confirmation
* @param {int} confID - The ID of the confirmation in question
* @param {int} time - The unix timestamp with which the following key was generated
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "details" (this key can be reused)
* @param {SteamCommunity~getConfirmationOfferID} callback
*/
SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, callback) {
request(this, "details/" + confID, key, time, "details", null, true, function(err, body) {
if(err) {
callback(err);
return;
}
if(!body.success) {
callback(new Error("Cannot load confirmation details"));
return;
}
var $ = Cheerio.load(body.html);
var offer = $('.tradeoffer');
if(offer.length < 1) {
callback(null, null);
return;
}
callback(null, offer.attr('id').split('_')[1]);
});
};
/**
* @callback SteamCommunity~getConfirmationOfferID
* @param {Error|null} err - An Error object on failure, or null on success
* @param {string} offerID - The trade offer ID associated with the specified confirmation, or null if not for an offer
*/
/**
* Confirm or cancel a given confirmation.
* @param {int} confID - The ID of the confirmation in question
* @param {string} confKey - The confirmation key associated with the confirmation in question (not a TOTP key, the `key` property of CConfirmation)
* @param {int} time - The unix timestamp with which the following key was generated
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "allow" (if accepting) or "cancel" (if not accepting)
* @param {boolean} accept - true if you want to accept the confirmation, false if you want to cancel it
* @param {SteamCommunity~genericErrorCallback} callback - Called when the request is complete
*/
SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time, key, accept, callback) {
request(this, "ajaxop", key, time, accept ? "allow" : "cancel", {
"op": accept ? "allow" : "cancel",
"cid": confID,
"ck": confKey
}, true, function(err, body) {
if(!callback) {
return;
}
if(err) {
callback(err);
return;
}
if(body.success) {
callback(null);
return;
}
if(body.message) {
callback(new Error(body.message));
return;
}
callback(new Error("Could not act on confirmation"));
});
};
function request(community, url, key, time, tag, params, json, callback) {
params = params || {};
params.p = "android:" + require('crypto').randomBytes(16).toString('hex');
params.a = community.steamID.getSteamID64();
params.k = key;
params.t = time;
params.m = "android";
params.tag = tag;
community.request.get({
"uri": "https://steamcommunity.com/mobileconf/" + url,
"qs": params,
"json": !!json
}, function(err, response, body) {
if(community._checkHttpError(err, response, callback)) {
return;
}
callback(null, body);
});
}
// Confirmation checker
/**
* 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, identitySecret) {
this._confirmationPollInterval = pollInterval;
this._knownConfirmations = this._knownConfirmations || {};
this._confirmationKeys = this._confirmationKeys || {};
this._identitySecret = identitySecret;
if(this._confirmationTimer) {
clearTimeout(this._confirmationTimer);
}
setTimeout(this.checkConfirmations.bind(this), 500);
};
/**
* Stop automatically polling our confirmations.
*/
SteamCommunity.prototype.stopConfirmationChecker = function() {
if(this._confirmationPollInterval) {
delete this._confirmationPollInterval;
}
if(this._identitySecret) {
delete this._identitySecret;
}
if(this._confirmationTimer) {
clearTimeout(this._confirmationTimer);
delete this._confirmationTimer;
}
};
/**
* Run the confirmation checker right now instead of waiting for the next poll.
* Useful to call right after you send/accept an offer that needs confirmation.
*/
SteamCommunity.prototype.checkConfirmations = function() {
if(this._confirmationTimer) {
clearTimeout(this._confirmationTimer);
delete this._confirmationTimer;
}
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();
return;
}
self.getConfirmations(key.time, key.key, function(err, confirmations) {
if(err) {
resetTimer();
return;
}
var known = self._knownConfirmations;
var newOnes = confirmations.filter(function(conf) {
return !known[conf.id];
});
if(newOnes.length < 1) {
resetTimer();
return; // No new ones
}
// We have new confirmations! Grab a key to get details.
self._confirmationCheckerGetKey('details', function(err, key) {
newOnes.forEach(function(conf) {
self._knownConfirmations[conf.id] = conf; // Add it to our list of known confirmations
if(err) {
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;
self._confirmationQueue.push(conf);
});
}
});
resetTimer();
});
});
});
function resetTimer() {
if(self._confirmationPollInterval) {
self._confirmationTimer = setTimeout(self.checkConfirmations.bind(self), self._confirmationPollInterval);
}
}
function handleNewConfirmation(conf, handleNumber) {
self._knownConfirmations[conf.id] = conf;
// Delay them by 1 second per new confirmation that we see, so that keys won't be the same.
setTimeout(function() {
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'];
// See if we already have a key that we can reuse.
if(reusable.indexOf(tag) != -1 && existing && (Date.now() - (existing.time * 1000) < (1000 * 60 * 5))) {
callback(null, existing);
return;
}
// We need a fresh one
var self = this;
this.emit('confKeyNeeded', tag, function(err, time, key) {
if(err) {
callback(err);
return;
}
self._confirmationKeys[tag] = {"time": time, "key": key};
callback(null, {"time": time, "key": key});
});
};

View File

@@ -203,7 +203,7 @@ SteamCommunity.prototype.scheduleGroupEvent = function(gid, name, type, descript
var self = this;
this.request.post({
"uri": "https://steamcommunity.com/gid/" + this.steamID.toString() + "/eventEdit",
"uri": "https://steamcommunity.com/gid/" + gid.toString() + "/eventEdit",
"form": form
}, function(err, response, body) {
if(!callback) {

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

@@ -101,10 +101,10 @@ SteamCommunity.prototype.editProfile = function(settings, callback) {
break;
case 'primaryGroup':
if(typeof settings[i] === 'object' && settings[i].accountid) {
values.primary_group_steamid = settings[i].accountid;
if(typeof settings[i] === 'object' && settings[i].getSteamID64) {
values.primary_group_steamid = settings[i].getSteamID64();
} else {
values.primary_group_steamid = new SteamID(settings[i]).accountid;
values.primary_group_steamid = new SteamID(settings[i]).getSteamID64();
}
break;
@@ -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;
}
}

159
components/twofactor.js Normal file
View File

@@ -0,0 +1,159 @@
var SteamTotp = require('steam-totp');
var SteamCommunity = require('../index.js');
var ETwoFactorTokenType = {
"None": 0, // No token-based two-factor authentication
"ValveMobileApp": 1, // Tokens generated using Valve's special charset (5 digits, alphanumeric)
"ThirdParty": 2 // Tokens generated using literally everyone else's standard charset (6 digits, numeric). This is disabled.
};
SteamCommunity.prototype.enableTwoFactor = function(callback) {
var self = this;
this.getWebApiOauthToken(function(err, token) {
if(err) {
callback(err);
return;
}
// Create a random device ID hash
var hash = require('crypto').createHash('sha1');
hash.update(self.steamID.getSteamID64());
hash = hash.digest('hex');
self.request.post({
"uri": "https://api.steampowered.com/ITwoFactorService/AddAuthenticator/v1/",
"form": {
"steamid": self.steamID.getSteamID64(),
"access_token": token,
"authenticator_time": Math.floor(Date.now() / 1000),
"authenticator_type": ETwoFactorTokenType.ValveMobileApp,
"device_identifier": 'android:' + hash,
"sms_phone_id": "1"
},
"json": true
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(!body.response) {
callback(new Error("Malformed response"));
return;
}
if(body.response.status != 1) {
var error = new Error("Error " + body.response.status);
error.eresult = body.response.status;
callback(error);
return;
}
callback(null, body.response);
});
});
};
SteamCommunity.prototype.finalizeTwoFactor = function(secret, activationCode, callback) {
var attemptsLeft = 30;
var diff = 0;
var self = this;
this.getWebApiOauthToken(function(err, token) {
if(err) {
callback(err);
return;
}
finalize(token);
});
function finalize(token) {
var code = SteamTotp.generateAuthCode(secret, diff);
self.request.post({
"uri": "https://api.steampowered.com/ITwoFactorService/FinalizeAddAuthenticator/v1/",
"form": {
"steamid": self.steamID.getSteamID64(),
"access_token": token,
"authenticator_code": code,
"authenticator_time": Math.floor(Date.now() / 1000),
"activation_code": activationCode
},
"json": true
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(!body.response) {
callback(new Error("Malformed response"));
return;
}
body = body.response;
if(body.server_time) {
diff = body.server_time - Math.floor(Date.now() / 1000);
}
if(body.status == 89) {
callback(new Error("Invalid activation code"));
} else if(body.want_more) {
attemptsLeft--;
diff += 30;
finalize(token);
} else if(!body.success) {
callback(new Error("Error " + body.status));
} else {
callback(null);
}
});
}
};
SteamCommunity.prototype.disableTwoFactor = function(revocationCode, callback) {
var self = this;
this.getWebApiOauthToken(function(err, token) {
if(err) {
callback(err);
return;
}
self.request.post({
"uri": "https://api.steampowered.com/ITwoFactorService/RemoveAuthenticator/v1/",
"form": {
"steamid": self.steamID.getSteamID64(),
"access_token": token,
"revocation_code": revocationCode,
"steamguard_scheme": 1
},
"json": true
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(!body.response) {
callback(new Error("Malformed response"));
return;
}
if(!body.response.success) {
callback(new Error("Request failed"));
return;
}
if(body.response.status == 1) {
callback(null);
return;
}
var error = new Error("Cannot remove authenticator (" + body.response.status + ")");
error.eresult = body.response.status;
callback(error);
});
});
};

View File

@@ -156,7 +156,7 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) {
if(body.success) {
callback(null);
} else if(bpdy.error) {
} else if(body.error) {
callback(new Error(body.error));
} else {
callback(new Error("Unknown error"));

66
components/webapi.js Normal file
View File

@@ -0,0 +1,66 @@
var SteamCommunity = require('../index.js');
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
var self = this;
this.request({
"uri": "https://steamcommunity.com/dev/apikey",
"followRedirect": false
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
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
self.request.post('https://steamcommunity.com/dev/registerkey', {
"form": {
"domain": domain,
"agreeToTerms": "agreed",
"sessionid": self.getSessionID(),
"Submit": "Register"
}
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
self.getWebApiKey(domain, callback);
});
}
});
};
SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
var self = this;
if( this.oAuthToken ) {
return callback( null, this.oAuthToken );
}
// Pull an oauth token from the webchat UI
this.request("https://steamcommunity.com/chat", function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(self._checkCommunityError(body, callback)) {
return;
}
var match = body.match(/"([0-9a-f]{32})"/);
if (!match) {
callback(new Error("Malformed response"));
return;
}
callback(null, match[1]);
});
};

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();
});
});
}

154
index.js
View File

@@ -3,6 +3,8 @@ 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;
@@ -14,7 +16,14 @@ function SteamCommunity(localAddress) {
this._captchaGid = -1;
this.chatState = SteamCommunity.ChatState.Offline;
var defaults = {"jar": this._jar, "timeout": 50000};
var defaults = {
"jar": this._jar,
"timeout": 50000,
"headers": {
"User-Agent": USER_AGENT
}
};
if(localAddress) {
defaults.localAddress = localAddress;
}
@@ -35,8 +44,27 @@ SteamCommunity.prototype.login = function(details, callback) {
}
var self = this;
this.request.post("https://steamcommunity.com/login/getrsakey/", {"form": {"username": details.accountName}}, function(err, response, body) {
// 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, */*"
};
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": {
"username": details.accountName
},
"headers": mobileHeaders
}, function(err, response, body) {
// Remove the mobile cookies
if(err) {
deleteMobileCookies();
callback(err);
return;
}
@@ -45,9 +73,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);
@@ -57,19 +92,24 @@ SteamCommunity.prototype.login = function(details, callback) {
"captchagid": self._captchaGid,
"emailauth": details.authCode || "",
"emailsteamid": "",
"loginfriendlyname": "",
"password": hex2b64(key.encrypt(details.password)),
"remember_login": "true",
"rsatimestamp": json.timestamp,
"twofactorcode": details.twoFactorCode || "",
"username": details.accountName
"username": details.accountName,
"oauth_client_id": "DE45CD61",
"oauth_scope": "read_profile write_profile read_client write_client",
"loginfriendlyname": "#login_emailauth_friendlyname_mobile"
};
self.request.post({
"uri": "https://steamcommunity.com/login/dologin/",
"json": true,
"form": form
"form": form,
"headers": mobileHeaders
}, function(err, response, body) {
deleteMobileCookies();
if(self._checkHttpError(err, response, callback)) {
return;
}
@@ -94,9 +134,12 @@ SteamCommunity.prototype.login = function(details, callback) {
callback(new Error(body.message || "Unknown error"));
} else {
var sessionID = generateSessionID();
var oAuth = JSON.parse( body.oauth );
self._jar.setCookie(Request.cookie('sessionid=' + sessionID), 'http://steamcommunity.com');
self.steamID = new SteamID(body.transfer_parameters.steamid);
self.steamID = new SteamID(oAuth.steamid);
self.oAuthToken = oAuth.oauth_token;
var cookies = self._jar.getCookieString("https://steamcommunity.com").split(';').map(function(cookie) {
return cookie.trim();
});
@@ -111,10 +154,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) {
@@ -144,46 +230,8 @@ SteamCommunity.prototype.getSessionID = function() {
};
function generateSessionID() {
return Math.floor(Math.random() * 1000000000);
};
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
var self = this;
this.request({
"uri": "https://steamcommunity.com/dev/apikey",
"followRedirect": false
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
if(body.match(/<h2>Access Denied<\/h2>/)) {
return callback("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
self.request.post('https://steamcommunity.com/dev/registerkey', {
"form": {
"domain": domain,
"agreeToTerms": "agreed",
"sessionid": self.getSessionID(),
"Submit": "Register"
}
}, function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
self.getWebApiKey(domain, callback);
});
}
});
};
return require('crypto').randomBytes(12).toString('hex');
}
SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
this.request.post("https://steamcommunity.com/parental/ajaxunlock", {
@@ -213,6 +261,7 @@ SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
};
SteamCommunity.prototype.getNotifications = function(callback) {
var self = this;
this.request.get("https://steamcommunity.com/actions/RefreshNotificationArea", function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
@@ -248,6 +297,7 @@ SteamCommunity.prototype.getNotifications = function(callback) {
};
SteamCommunity.prototype.resetItemNotifications = function(callback) {
var self = this;
this.request.get("https://steamcommunity.com/my/inventory", function(err, response, body) {
if(!callback) {
return;
@@ -297,7 +347,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;
}
@@ -332,7 +382,15 @@ require('./components/market.js');
require('./components/groups.js');
require('./components/users.js');
require('./components/inventoryhistory.js');
require('./components/webapi.js');
require('./components/twofactor.js');
require('./components/confirmations.js');
require('./classes/CMarketItem.js');
require('./classes/CMarketSearchResult.js');
require('./classes/CSteamGroup.js');
require('./classes/CSteamUser.js');
/**
@callback SteamCommunity~genericErrorCallback
@param {Error|null} err - An Error object on failure, or null on success
*/

View File

@@ -1,6 +1,6 @@
{
"name": "steamcommunity",
"version": "3.9.2",
"version": "3.16.0",
"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",
@@ -18,6 +18,7 @@
"steamid": "^0.3.1",
"xml2js": "^0.4.11",
"cheerio": "^0.19.0",
"async": "^1.4.2"
"async": "^1.4.2",
"steam-totp": "^1.0.0"
}
}