-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses_Auth.js.html
More file actions
360 lines (305 loc) · 15.7 KB
/
Copy pathclasses_Auth.js.html
File metadata and controls
360 lines (305 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: classes/Auth.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: classes/Auth.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>Auth.prototype.__proto__ = require('events').EventEmitter.prototype;
const SteamTotp = require('steam-totp');
var privateStore = {};
/**
* A class to handle all authentication functions for a bot account
* @param BotAccount
* @param accountDetails
* @param logger
* @constructor
*/
function Auth(BotAccount, accountDetails, logger) {
var self = this;
self.logger = logger;
self.BotAccount = BotAccount;
self.community = BotAccount.community;
self.store = BotAccount.store;
self.accountName = BotAccount.getAccountName();
accountDetails.accountName = self.accountName;
if (BotAccount.password)
accountDetails.password = BotAccount.password;
self.loggedIn = false;
// Create an object to manage this instance's state and
// use a unique ID to reference it in the private store.
privateStore[self.accountName] = {};
// Store private stuff in the private store
// instead of on `this`.
privateStore[self.accountName].accountDetails = accountDetails;
self.BotAccount.client.on('loggedOn', function(details, parental){
self.emit('loggedInNodeSteam', details);
self.emit('debug', 'Logged into Steam via SteamClient.');
});
self.BotAccount.client.on('loginKey', function(loginKey){
privateStore[self.accountName].accountDetails.loginKey = loginKey;
self.emit('updatedAccountDetails', privateStore[self.accountName].accountDetails);
self.emit('debug', 'Received a loginKey. This key must be removed if changing ip\'s.');
});
self.BotAccount.client.on('error', function(error){
self.emit('debug', error);
});
Auth.prototype.enableTwoFactor = function (callback) {
var self = this;
self.emit('enablingTwoFactorAuth');
self.logger.log('debug', 'Enabling two factor authentication for %j', self.username);
self.community.enableTwoFactor(function (err, response) {
if (err) {
self.logger.log('error', 'Failed to enable two factor authentication for %j due to : %j', self.username, err);
return callback(err, undefined);
}
self.logger.log('debug', 'Enabled two factor authentication for %j', self.username);
privateStore[self.accountName].accountDetails.shared_secret = response.shared_secret;
privateStore[self.accountName].accountDetails.identity_secret = response.identity_secret;
privateStore[self.accountName].accountDetails.revocation_code = response.revocation_code;
self.emit('enabledTwoFactorAuth');
return callback(err, response);
});
};
Auth.prototype.disableTwoFactor = function (callback) {
var self = this;
self.emit('disablingTwoFactorAuth');
self.logger.log('debug', 'Disabling two factor authentication for %j', self.getAccountName());
if (!privateStore[self.accountName].accountDetails.revocation_code)
return callback({Error: "There is no revocation code saved."}, undefined);
self.community.disableTwoFactor(privateStore[self.accountName].accountDetails.revocation_code, function (err) {
if (err)
return callback(err, undefined);
self.logger.log('debug', 'Disabled two factor authentication for %j', self.getAccountName());
privateStore.splice(privateStore.indexOf(self.accountName, 1));
self.emit('disabledTwoFactorAuth', response);
return callback(undefined, response);
});
};
Auth.prototype.finalizeTwoFactor = function (activationCode, callbackErrorOnly) {
var self = this;
self.emit('finalizedTwoFactorAuth');
self.community.finalizeTwoFactor(privateStore[self.accountName].accountDetails.shared_secret, activationCode, function (err) {
callbackErrorOnly(err, privateStore[self.accountName].accountDetails);
});
};
/**
* Login to account using supplied details (2FactorCode, authcode, or captcha)
* @param details
* @callback {callbackErrorOnly}
*/
Auth.prototype.loginAccount = function (details, callbackErrorOnly) {
var self = this;
self.emit('loggingIn');
if (self.has_shared_secret()) {
privateStore[self.accountName].accountDetails.twoFactorCode = self.generateMobileAuthenticationCode();
}
if (details != undefined) {
if (details.authCode != undefined)
privateStore[self.accountName].accountDetails.authCode = details.authCode;
if (details.captcha != undefined)
privateStore[self.accountName].accountDetails.captcha = details.captcha;
}
if (privateStore[self.accountName].accountDetails.steamguard && privateStore[self.accountName].accountDetails.oAuthToken) {
self.community.oAuthLogin(privateStore[self.accountName].accountDetails.steamguard, privateStore[self.accountName].accountDetails.oAuthToken, function (err, sessionID, cookies) {
if (err) {
if (err != undefined && err.Error == "HTTP error 429") {
self.emit('rateLimitedSteam');
self.logger.log('error', "Rate limited by Steam - Delaying request.");
self.BotAccount.addToQueue('ratelimit', self, self.loginAccount, [details, callbackErrorOnly]);
}
self.logger.log('error', "Failed to login into account via oAuth due to " + err);
if (callbackErrorOnly != undefined)
return callbackErrorOnly(err);
}
else {
self.loggedIn = true;
self.sessionid = sessionID;
if (privateStore[self.accountName].accountDetails.password) {
self.BotAccount.client.logOn({
accountName: self.accountName,
password: privateStore[self.accountName].accountDetails.password,
authCode: privateStore[self.accountName].accountDetails.authCode,
loginKey: privateStore[self.accountName].accountDetails.loginKey,
twoFactorCode: privateStore[self.accountName].accountDetails.twoFactorCode,
rememberPassword: true,
logonID: 1337,
machineName: "node-steam-bot-manager",
});
}
self.BotAccount.loggedInAccount(cookies, sessionID, function(err, steamid){
privateStore[self.accountName].accountDetails.steamid64 = steamid.getSteamID64();
self.emit('updatedAccountDetails', privateStore[self.accountName].accountDetails);
if (callbackErrorOnly != undefined)
return callbackErrorOnly(err);
});
}
});
}
else {
self.community.login(privateStore[self.accountName].accountDetails, function (err, sessionID, cookies, steamguardGen, oAuthTokenGen) {
if (err) {
if (err != undefined && err.Error == "HTTP error 429") {
self.emit('rateLimitedSteam');
self.logger.log('error', "Rate limited by Steam - Delaying request.");
self.BotAccount.addToQueue('ratelimit', self, self.loginAccount, [details, callbackErrorOnly]);
}
if (privateStore[self.accountName].accountDetails.password) {
self.BotAccount.client.logOn({
accountName: self.accountName,
password: privateStore[self.accountName].accountDetails.password,
authCode: privateStore[self.accountName].accountDetails.authCode,
twoFactorCode: privateStore[self.accountName].accountDetails.twoFactorCode,
// loginKey: privateStore[self.accountName].accountDetails.loginKey,
rememberPassword: true,
logonID: 1337,
machineName: "node-steam-bot-manager",
});
}
self.emit('updatedAccountDetails', privateStore[self.accountName].accountDetails);
self.logger.log('error', "Failed to login into account due to " + err);
if (callbackErrorOnly != undefined)
callbackErrorOnly(err);
return;
}
privateStore[self.accountName].accountDetails.steamguard = steamguardGen;
privateStore[self.accountName].accountDetails.oAuthToken = oAuthTokenGen;
self.loggedIn = true;
self.sessionid = sessionID;
self.BotAccount.loggedInAccount(cookies, sessionID, function(err, steamid){
privateStore[self.accountName].accountDetails.steamid64 = steamid.getSteamID64();
self.emit('updatedAccountDetails', privateStore[self.accountName].accountDetails);
if (callbackErrorOnly != undefined)
return callbackErrorOnly(err);
});
});
}
};
/**
* Logout from chat of the botAccount
* @param details
*/
Auth.prototype.logoutAccount = function () {
var self = this;
self.emit('loggingOut');
self.community.chatLogoff();
};
/**
* Sets the revocation code and returns it if successful (null if it fails validity checks).
* @param revocationCode
* @returns {String}
*/
Auth.prototype.setRevocationCode = function (revocationCode) {
var self = this;
if (revocationCode.indexOf("R") == 0 && revocationCode.length == 6)
return privateStore[self.accountName].accountDetails.revocation_code = revocationCode;
else
return undefined;
};
Auth.prototype.has_shared_secret = function () {
var self = this;
return !!privateStore[self.accountName].accountDetails.identity_secret;
};
/**
* Generate two-factor-authentication code used for logging in.
* @returns {Error | String}
*/
Auth.prototype.generateMobileAuthenticationCode = function () {
var self = this;
if (privateStore[self.accountName].accountDetails.shared_secret)
return SteamTotp.generateAuthCode(privateStore[self.accountName].accountDetails.shared_secret);
else
return new Error("Failed to generate authentication code. Enable 2-factor-authentication via this tool.");
};
/**
*
* @param time - Current time of trade (Please use getUnixTime())
* @param tag - Type of confirmation required ("conf" to load the confirmations page, "details" to load details about a trade, "allow" to confirm a trade, "cancel" to cancel it.)
* @returns {Error}
*/
Auth.prototype.generateMobileConfirmationCode = function (time, tag) {
var self = this;
if (privateStore[self.accountName].accountDetails.identity_secret)
return SteamTotp.generateConfirmationKey(privateStore[self.accountName].accountDetails.identity_secret, time, tag);
else
return new Error("Failed to generate confirmation code. Enable 2-factor-authentication via this tool.");
};
/**
* This is meant to be a private method that updates account details securely (triggers an event to botAccount for a save, without revealing account information to preying eyes - can be bypassed, but simply makes it more challenging to be done without editing the the manager's code)
* @param newDetails
*/
Auth.prototype._updateAccountDetails = function (newDetails) {
// We will loop through all new details and ensure they do no edit any protected details
var self = this;
var protectedDetails = ["username", "accountName", "oAuthToken", "steamguard", "password", "shared_secret", "identity_secret", "revocation_code", "steamid64", "loginKey", "displayName"];
for (var newDetail in newDetails) {
if (newDetails.hasOwnProperty(newDetail))
if (protectedDetails.indexOf(newDetail) == -1)
if (newDetails.hasOwnProperty(newDetail))
privateStore[self.accountName].accountDetails[newDetail] = newDetails[newDetail];
}
self.emit('updatedAccountDetails', privateStore[self.accountName].accountDetails);
};
/**
* @callback confirmationsCallback
* @param {Error} error - An error message if the process failed, undefined if successful
* @param {Array} confirmations - An array of Confirmations
*/
/**
* Get outstanding confirmations
* @param time
* @param key
* @param confirmationsCallback
*/
Auth.prototype.getConfirmations = function (time, key, confirmationsCallback) {
var self = this;
self.community.getConfirmations(time, key, confirmationsCallback);
};
Auth.prototype.respondToConfirmation = function (confID, confKey, time, key, accept, callback) {
var self = this;
self.community.respondToConfirmation(confID, confKey, time, key, accept, callback);
};
}
/**
* Get system time... for use with auth.
* @param timeOffset
* @returns {*}
*/
Auth.prototype.getTime = function (timeOffset) {
return Math.floor(Date.now() / 1000) + timeOffset;
};
/**
* Get time offset using steam... for use with auth.
* @param timeOffset
* @returns {*}
*/
Auth.prototype.getTimeOffset = function (callback) {
SteamTotp.getTimeOffset(callback);
};
module.exports = Auth;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Auth.html">Auth</a></li><li><a href="Bot.html">Bot</a></li><li><a href="global.html#BotManager">BotManager</a></li><li><a href="Community.html">Community</a></li><li><a href="Friends.html">Friends</a></li><li><a href="GUI_Handler.html">GUI_Handler</a></li><li><a href="Profile.html">Profile</a></li><li><a href="Request.html">Request</a></li><li><a href="Trade.html">Trade</a></li></ul><h3>Events</h3><ul><li><a href="Bot.html#event:chatMessage">chatMessage</a></li><li><a href="Bot.html#event:loggedIn">loggedIn</a></li><li><a href="Bot.html#event:newOffer">newOffer</a></li><li><a href="Bot.html#event:offerChanged">offerChanged</a></li><li><a href="Bot.html#event:offerList">offerList</a></li><li><a href="Bot.html#event:sentOfferChanged">sentOfferChanged</a></li><li><a href="Bot.html#event:tradeOffers">tradeOffers</a></li></ul><h3>Global</h3><ul><li><a href="global.html#webserver">webserver</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Sat Oct 28 2017 11:52:44 GMT-0400 (Eastern Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>