steamcommunity 3.44.4 → 3.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/helpers.js +68 -56
- package/components/twofactor.js +96 -103
- package/components/webapi.js +118 -57
- package/examples/disable_twofactor.js +27 -8
- package/examples/enable_twofactor.js +40 -21
- package/index.js +10 -0
- package/package.json +1 -1
package/components/helpers.js
CHANGED
|
@@ -1,56 +1,68 @@
|
|
|
1
|
-
const EResult = require('../resources/EResult.js');
|
|
2
|
-
|
|
3
|
-
exports.isSteamID = function(input) {
|
|
4
|
-
var keys = Object.keys(input);
|
|
5
|
-
if (keys.length != 4) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Make sure it has the keys we expect
|
|
10
|
-
keys = keys.filter(function(item) {
|
|
11
|
-
return ['universe', 'type', 'instance', 'accountid'].indexOf(item) != -1;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
return keys.length == 4;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
exports.decodeSteamTime = function(time) {
|
|
18
|
-
var date = new Date();
|
|
19
|
-
|
|
20
|
-
if (time.includes("@")) {
|
|
21
|
-
var parts = time.split('@');
|
|
22
|
-
if (!parts[0].includes(",")) {
|
|
23
|
-
// no year, assume current year
|
|
24
|
-
parts[0] += ", " + date.getFullYear();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
date = new Date(parts.join('@').replace(/(am|pm)/, ' $1') + " UTC"); // add a space so JS can decode it
|
|
28
|
-
} else {
|
|
29
|
-
// Relative date
|
|
30
|
-
var amount = time.replace(/(\d) (minutes|hour|hours) ago/, "$1");
|
|
31
|
-
|
|
32
|
-
if(time.includes("minutes")) {
|
|
33
|
-
date.setMinutes(date.getMinutes() - amount);
|
|
34
|
-
} else if(time.match(/hour|hours/)) {
|
|
35
|
-
date.setHours(date.getHours() - amount);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return date;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get an Error object for a particular EResult
|
|
44
|
-
* @param {int} eresult
|
|
45
|
-
* @returns {null|Error}
|
|
46
|
-
*/
|
|
47
|
-
exports.eresultError = function(eresult) {
|
|
48
|
-
if (eresult == EResult.OK) {
|
|
49
|
-
// no error
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var err = new Error(EResult[eresult] || ("Error " + eresult));
|
|
54
|
-
err.eresult = eresult;
|
|
55
|
-
return err;
|
|
56
|
-
};
|
|
1
|
+
const EResult = require('../resources/EResult.js');
|
|
2
|
+
|
|
3
|
+
exports.isSteamID = function(input) {
|
|
4
|
+
var keys = Object.keys(input);
|
|
5
|
+
if (keys.length != 4) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Make sure it has the keys we expect
|
|
10
|
+
keys = keys.filter(function(item) {
|
|
11
|
+
return ['universe', 'type', 'instance', 'accountid'].indexOf(item) != -1;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return keys.length == 4;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.decodeSteamTime = function(time) {
|
|
18
|
+
var date = new Date();
|
|
19
|
+
|
|
20
|
+
if (time.includes("@")) {
|
|
21
|
+
var parts = time.split('@');
|
|
22
|
+
if (!parts[0].includes(",")) {
|
|
23
|
+
// no year, assume current year
|
|
24
|
+
parts[0] += ", " + date.getFullYear();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
date = new Date(parts.join('@').replace(/(am|pm)/, ' $1') + " UTC"); // add a space so JS can decode it
|
|
28
|
+
} else {
|
|
29
|
+
// Relative date
|
|
30
|
+
var amount = time.replace(/(\d) (minutes|hour|hours) ago/, "$1");
|
|
31
|
+
|
|
32
|
+
if(time.includes("minutes")) {
|
|
33
|
+
date.setMinutes(date.getMinutes() - amount);
|
|
34
|
+
} else if(time.match(/hour|hours/)) {
|
|
35
|
+
date.setHours(date.getHours() - amount);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return date;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get an Error object for a particular EResult
|
|
44
|
+
* @param {int} eresult
|
|
45
|
+
* @returns {null|Error}
|
|
46
|
+
*/
|
|
47
|
+
exports.eresultError = function(eresult) {
|
|
48
|
+
if (eresult == EResult.OK) {
|
|
49
|
+
// no error
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var err = new Error(EResult[eresult] || ("Error " + eresult));
|
|
54
|
+
err.eresult = eresult;
|
|
55
|
+
return err;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
exports.decodeJwt = function(jwt) {
|
|
59
|
+
let parts = jwt.split('.');
|
|
60
|
+
if (parts.length != 3) {
|
|
61
|
+
throw new Error('Invalid JWT');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let standardBase64 = parts[1].replace(/-/g, '+')
|
|
65
|
+
.replace(/_/g, '/');
|
|
66
|
+
|
|
67
|
+
return JSON.parse(Buffer.from(standardBase64, 'base64').toString('utf8'));
|
|
68
|
+
}
|
package/components/twofactor.js
CHANGED
|
@@ -2,158 +2,151 @@ var SteamTotp = require('steam-totp');
|
|
|
2
2
|
var SteamCommunity = require('../index.js');
|
|
3
3
|
|
|
4
4
|
var ETwoFactorTokenType = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
None: 0, // No token-based two-factor authentication
|
|
6
|
+
ValveMobileApp: 1, // Tokens generated using Valve's special charset (5 digits, alphanumeric)
|
|
7
|
+
ThirdParty: 2 // Tokens generated using literally everyone else's standard charset (6 digits, numeric). This is disabled.
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
SteamCommunity.prototype.enableTwoFactor = function(callback) {
|
|
11
|
-
|
|
11
|
+
this._verifyMobileAccessToken();
|
|
12
12
|
|
|
13
|
-
this.
|
|
14
|
-
|
|
13
|
+
if (!this.mobileAccessToken) {
|
|
14
|
+
callback(new Error('No mobile access token available. Provide one by calling setMobileAppAccessToken()'));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.httpRequestPost({
|
|
19
|
+
uri: "https://api.steampowered.com/ITwoFactorService/AddAuthenticator/v1/?access_token=" + this.mobileAccessToken,
|
|
20
|
+
// TODO: Send this as protobuf to more closely mimic official app behavior
|
|
21
|
+
form: {
|
|
22
|
+
steamid: this.steamID.getSteamID64(),
|
|
23
|
+
authenticator_time: Math.floor(Date.now() / 1000),
|
|
24
|
+
authenticator_type: ETwoFactorTokenType.ValveMobileApp,
|
|
25
|
+
device_identifier: SteamTotp.getDeviceID(this.steamID),
|
|
26
|
+
sms_phone_id: '1'
|
|
27
|
+
},
|
|
28
|
+
json: true
|
|
29
|
+
}, (err, response, body) => {
|
|
30
|
+
if (err) {
|
|
15
31
|
callback(err);
|
|
16
32
|
return;
|
|
17
33
|
}
|
|
18
34
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"access_token": token,
|
|
24
|
-
"authenticator_time": Math.floor(Date.now() / 1000),
|
|
25
|
-
"authenticator_type": ETwoFactorTokenType.ValveMobileApp,
|
|
26
|
-
"device_identifier": SteamTotp.getDeviceID(self.steamID),
|
|
27
|
-
"sms_phone_id": "1"
|
|
28
|
-
},
|
|
29
|
-
"json": true
|
|
30
|
-
}, function(err, response, body) {
|
|
31
|
-
if (err) {
|
|
32
|
-
callback(err);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if(!body.response) {
|
|
37
|
-
callback(new Error("Malformed response"));
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
35
|
+
if (!body.response) {
|
|
36
|
+
callback(new Error('Malformed response'));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
if (body.response.status != 1) {
|
|
41
|
+
var error = new Error('Error ' + body.response.status);
|
|
42
|
+
error.eresult = body.response.status;
|
|
43
|
+
callback(error);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
47
|
+
callback(null, body.response);
|
|
48
|
+
}, 'steamcommunity');
|
|
51
49
|
};
|
|
52
50
|
|
|
53
51
|
SteamCommunity.prototype.finalizeTwoFactor = function(secret, activationCode, callback) {
|
|
54
|
-
|
|
55
|
-
var diff = 0;
|
|
52
|
+
this._verifyMobileAccessToken();
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
54
|
+
if (!this.mobileAccessToken) {
|
|
55
|
+
callback(new Error('No mobile access token available. Provide one by calling setMobileAppAccessToken()'));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
63
58
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
callback(err);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
59
|
+
let attemptsLeft = 30;
|
|
60
|
+
let diff = 0;
|
|
69
61
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
});
|
|
62
|
+
let finalize = () => {
|
|
63
|
+
let code = SteamTotp.generateAuthCode(secret, diff);
|
|
74
64
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"access_token": token,
|
|
83
|
-
"authenticator_code": code,
|
|
84
|
-
"authenticator_time": Math.floor(Date.now() / 1000),
|
|
85
|
-
"activation_code": activationCode
|
|
65
|
+
this.httpRequestPost({
|
|
66
|
+
uri: 'https://api.steampowered.com/ITwoFactorService/FinalizeAddAuthenticator/v1/?access_token=' + this.mobileAccessToken,
|
|
67
|
+
form: {
|
|
68
|
+
steamid: this.steamID.getSteamID64(),
|
|
69
|
+
authenticator_code: code,
|
|
70
|
+
authenticator_time: Math.floor(Date.now() / 1000),
|
|
71
|
+
activation_code: activationCode
|
|
86
72
|
},
|
|
87
|
-
|
|
73
|
+
json: true
|
|
88
74
|
}, function(err, response, body) {
|
|
89
75
|
if (err) {
|
|
90
76
|
callback(err);
|
|
91
77
|
return;
|
|
92
78
|
}
|
|
93
79
|
|
|
94
|
-
if(!body.response) {
|
|
95
|
-
callback(new Error(
|
|
80
|
+
if (!body.response) {
|
|
81
|
+
callback(new Error('Malformed response'));
|
|
96
82
|
return;
|
|
97
83
|
}
|
|
98
84
|
|
|
99
85
|
body = body.response;
|
|
100
86
|
|
|
101
|
-
if(body.server_time) {
|
|
87
|
+
if (body.server_time) {
|
|
102
88
|
diff = body.server_time - Math.floor(Date.now() / 1000);
|
|
103
89
|
}
|
|
104
90
|
|
|
105
|
-
if(body.status == 89) {
|
|
106
|
-
callback(new Error(
|
|
91
|
+
if (body.status == 89) {
|
|
92
|
+
callback(new Error('Invalid activation code'));
|
|
107
93
|
} else if(body.want_more) {
|
|
108
94
|
attemptsLeft--;
|
|
109
95
|
diff += 30;
|
|
110
96
|
|
|
111
|
-
finalize(
|
|
97
|
+
finalize();
|
|
112
98
|
} else if(!body.success) {
|
|
113
|
-
callback(new Error(
|
|
99
|
+
callback(new Error('Error ' + body.status));
|
|
114
100
|
} else {
|
|
115
101
|
callback(null);
|
|
116
102
|
}
|
|
117
|
-
},
|
|
103
|
+
}, 'steamcommunity');
|
|
118
104
|
}
|
|
105
|
+
|
|
106
|
+
SteamTotp.getTimeOffset(function(err, offset, latency) {
|
|
107
|
+
if (err) {
|
|
108
|
+
callback(err);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
diff = offset;
|
|
113
|
+
finalize();
|
|
114
|
+
});
|
|
119
115
|
};
|
|
120
116
|
|
|
121
117
|
SteamCommunity.prototype.disableTwoFactor = function(revocationCode, callback) {
|
|
122
|
-
|
|
118
|
+
this._verifyMobileAccessToken();
|
|
123
119
|
|
|
124
|
-
this.
|
|
125
|
-
|
|
120
|
+
if (!this.mobileAccessToken) {
|
|
121
|
+
callback(new Error('No mobile access token available. Provide one by calling setMobileAppAccessToken()'));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.httpRequestPost({
|
|
126
|
+
uri: 'https://api.steampowered.com/ITwoFactorService/RemoveAuthenticator/v1/?access_token=' + this.mobileAccessToken,
|
|
127
|
+
form: {
|
|
128
|
+
steamid: this.steamID.getSteamID64(),
|
|
129
|
+
revocation_code: revocationCode,
|
|
130
|
+
steamguard_scheme: 1
|
|
131
|
+
},
|
|
132
|
+
json: true
|
|
133
|
+
}, function(err, response, body) {
|
|
134
|
+
if (err) {
|
|
126
135
|
callback(err);
|
|
127
136
|
return;
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
"access_token": token,
|
|
135
|
-
"revocation_code": revocationCode,
|
|
136
|
-
"steamguard_scheme": 1
|
|
137
|
-
},
|
|
138
|
-
"json": true
|
|
139
|
-
}, function(err, response, body) {
|
|
140
|
-
if (err) {
|
|
141
|
-
callback(err);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if(!body.response) {
|
|
146
|
-
callback(new Error("Malformed response"));
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
139
|
+
if (!body.response) {
|
|
140
|
+
callback(new Error('Malformed response'));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
149
143
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
144
|
+
if (!body.response.success) {
|
|
145
|
+
callback(new Error('Request failed'));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
154
148
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
149
|
+
// success = true means it worked
|
|
150
|
+
callback(null);
|
|
151
|
+
}, 'steamcommunity');
|
|
159
152
|
};
|
package/components/webapi.js
CHANGED
|
@@ -1,57 +1,118 @@
|
|
|
1
|
-
var SteamCommunity = require('../index.js');
|
|
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
|
-
|
|
1
|
+
var SteamCommunity = require('../index.js');
|
|
2
|
+
|
|
3
|
+
const Helpers = require('./helpers.js');
|
|
4
|
+
|
|
5
|
+
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
|
6
|
+
var self = this;
|
|
7
|
+
this.httpRequest({
|
|
8
|
+
"uri": "https://steamcommunity.com/dev/apikey?l=english",
|
|
9
|
+
"followRedirect": false
|
|
10
|
+
}, function(err, response, body) {
|
|
11
|
+
if (err) {
|
|
12
|
+
callback(err);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if(body.match(/<h2>Access Denied<\/h2>/)) {
|
|
17
|
+
return callback(new Error("Access Denied"));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if(body.match(/You must have a validated email address to create a Steam Web API key./)) {
|
|
21
|
+
return callback(new Error("You must have a validated email address to create a Steam Web API key."));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
|
|
25
|
+
if(match) {
|
|
26
|
+
// We already have an API key registered
|
|
27
|
+
callback(null, match[1]);
|
|
28
|
+
} else {
|
|
29
|
+
// We need to register a new API key
|
|
30
|
+
self.httpRequestPost('https://steamcommunity.com/dev/registerkey?l=english', {
|
|
31
|
+
"form": {
|
|
32
|
+
"domain": domain,
|
|
33
|
+
"agreeToTerms": "agreed",
|
|
34
|
+
"sessionid": self.getSessionID(),
|
|
35
|
+
"Submit": "Register"
|
|
36
|
+
}
|
|
37
|
+
}, function(err, response, body) {
|
|
38
|
+
if (err) {
|
|
39
|
+
callback(err);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
self.getWebApiKey(domain, callback);
|
|
44
|
+
}, "steamcommunity");
|
|
45
|
+
}
|
|
46
|
+
}, "steamcommunity");
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated No longer works. Will be removed in a future release.
|
|
51
|
+
* @param {function} callback
|
|
52
|
+
*/
|
|
53
|
+
SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
|
|
54
|
+
if (this.oAuthToken) {
|
|
55
|
+
return callback(null, this.oAuthToken);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
callback(new Error('This operation requires an OAuth token, which is no longer issued by Steam.'));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Sets an access_token generated by steam-session using EAuthTokenPlatformType.MobileApp.
|
|
63
|
+
* Required for some operations such as 2FA enabling and disabling.
|
|
64
|
+
* This will throw an Error if the provided token is not valid, was not generated for the MobileApp platform, is expired,
|
|
65
|
+
* or does not belong to the logged-in user account.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} token
|
|
68
|
+
*/
|
|
69
|
+
SteamCommunity.prototype.setMobileAppAccessToken = function(token) {
|
|
70
|
+
if (!this.steamID) {
|
|
71
|
+
throw new Error('Log on to steamcommunity before setting a mobile app access token');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let decodedToken = Helpers.decodeJwt(token);
|
|
75
|
+
|
|
76
|
+
if (!decodedToken.iss || !decodedToken.sub || !decodedToken.aud || !decodedToken.exp) {
|
|
77
|
+
throw new Error('Provided value is not a valid Steam access token');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (decodedToken.iss == 'steam') {
|
|
81
|
+
throw new Error('Provided token is a refresh token, not an access token');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (decodedToken.sub != this.steamID.getSteamID64()) {
|
|
85
|
+
throw new Error(`Provided token belongs to account ${decodedToken.sub}, but we are logged into ${this.steamID.getSteamID64()}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (decodedToken.exp < Math.floor(Date.now() / 1000)) {
|
|
89
|
+
throw new Error('Provided token is expired');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if ((decodedToken.aud || []).indexOf('mobile') == -1) {
|
|
93
|
+
throw new Error('Provided token is not valid for MobileApp platform type');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
this.mobileAccessToken = token;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Verifies that the mobile access token we already have set is still valid for current login.
|
|
101
|
+
*
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
SteamCommunity.prototype._verifyMobileAccessToken = function() {
|
|
105
|
+
if (!this.mobileAccessToken) {
|
|
106
|
+
// No access token, so nothing to do here.
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let decodedToken = Helpers.decodeJwt(this.mobileAccessToken);
|
|
111
|
+
|
|
112
|
+
let isTokenInvalid = decodedToken.sub != this.steamID.getSteamID64() // SteamID doesn't match
|
|
113
|
+
|| decodedToken.exp < Math.floor(Date.now() / 1000); // Token is expired
|
|
114
|
+
|
|
115
|
+
if (isTokenInvalid) {
|
|
116
|
+
delete this.mobileAccessToken;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
@@ -48,15 +48,34 @@ function doLogin(accountName, password, authCode, captcha, rCode) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
console.log('Logged on!');
|
|
51
|
-
community.disableTwoFactor('R' + rCode, (err) => {
|
|
52
|
-
if (err) {
|
|
53
|
-
console.log(err);
|
|
54
|
-
process.exit();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
51
|
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
if (community.mobileAccessToken) {
|
|
53
|
+
// If we already have a mobile access token, we don't need to prompt for one.
|
|
54
|
+
doRevoke(rCode);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log('You need to provide a mobile app access token to continue.');
|
|
59
|
+
console.log('You can generate one using steam-session (https://www.npmjs.com/package/steam-session).');
|
|
60
|
+
console.log('The access token needs to be generated using EAuthTokenPlatformType.MobileApp.');
|
|
61
|
+
console.log('Make sure you provide an *ACCESS* token, not a refresh token.');
|
|
62
|
+
|
|
63
|
+
rl.question('Access Token: ', (accessToken) => {
|
|
64
|
+
community.setMobileAppAccessToken(accessToken);
|
|
65
|
+
doRevoke(rCode);
|
|
60
66
|
});
|
|
61
67
|
});
|
|
62
68
|
}
|
|
69
|
+
|
|
70
|
+
function doRevoke(rCode) {
|
|
71
|
+
community.disableTwoFactor('R' + rCode, (err) => {
|
|
72
|
+
if (err) {
|
|
73
|
+
console.log(err);
|
|
74
|
+
process.exit();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log('Two-factor authentication disabled!');
|
|
79
|
+
process.exit();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -56,38 +56,57 @@ function doLogin(accountName, password, authCode, captcha) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
console.log('Logged on!');
|
|
59
|
-
community.enableTwoFactor((err, response) => {
|
|
60
|
-
if (err) {
|
|
61
|
-
if (err.eresult == EResult.Fail) {
|
|
62
|
-
console.log('Error: Failed to enable two-factor authentication. Do you have a phone number attached to your account?');
|
|
63
|
-
process.exit();
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
59
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
if (community.mobileAccessToken) {
|
|
61
|
+
// If we already have a mobile access token, we don't need to prompt for one.
|
|
62
|
+
doSetup();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
72
65
|
|
|
73
|
-
|
|
66
|
+
console.log('You need to provide a mobile app access token to continue.');
|
|
67
|
+
console.log('You can generate one using steam-session (https://www.npmjs.com/package/steam-session).');
|
|
68
|
+
console.log('The access token needs to be generated using EAuthTokenPlatformType.MobileApp.');
|
|
69
|
+
console.log('Make sure you provide an *ACCESS* token, not a refresh token.');
|
|
70
|
+
|
|
71
|
+
rl.question('Access Token: ', (accessToken) => {
|
|
72
|
+
community.setMobileAppAccessToken(accessToken);
|
|
73
|
+
doSetup();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function doSetup() {
|
|
79
|
+
community.enableTwoFactor((err, response) => {
|
|
80
|
+
if (err) {
|
|
81
|
+
if (err.eresult == EResult.Fail) {
|
|
82
|
+
console.log('Error: Failed to enable two-factor authentication. Do you have a phone number attached to your account?');
|
|
74
83
|
process.exit();
|
|
75
84
|
return;
|
|
76
85
|
}
|
|
77
86
|
|
|
78
|
-
if (
|
|
79
|
-
console.log(
|
|
87
|
+
if (err.eresult == EResult.RateLimitExceeded) {
|
|
88
|
+
console.log('Error: RateLimitExceeded. Try again later.');
|
|
80
89
|
process.exit();
|
|
81
90
|
return;
|
|
82
91
|
}
|
|
83
92
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
console.log(err);
|
|
94
|
+
process.exit();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (response.status != EResult.OK) {
|
|
99
|
+
console.log(`Error: Status ${response.status}`);
|
|
100
|
+
process.exit();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let filename = `twofactor_${community.steamID.getSteamID64()}.json`;
|
|
105
|
+
console.log(`Writing secrets to ${filename}`);
|
|
106
|
+
console.log(`Revocation code: ${response.revocation_code}`);
|
|
107
|
+
FS.writeFileSync(filename, JSON.stringify(response, null, '\t'));
|
|
88
108
|
|
|
89
|
-
|
|
90
|
-
});
|
|
109
|
+
promptActivationCode(response);
|
|
91
110
|
});
|
|
92
111
|
}
|
|
93
112
|
|
package/index.js
CHANGED
|
@@ -214,6 +214,12 @@ SteamCommunity.prototype.login = function(details, callback) {
|
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
216
|
|
|
217
|
+
/**
|
|
218
|
+
* @deprecated
|
|
219
|
+
* @param {string} steamguard
|
|
220
|
+
* @param {string} token
|
|
221
|
+
* @param {function} callback
|
|
222
|
+
*/
|
|
217
223
|
SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) {
|
|
218
224
|
steamguard = steamguard.split('||');
|
|
219
225
|
var steamID = new SteamID(steamguard[0]);
|
|
@@ -300,6 +306,10 @@ SteamCommunity.prototype.setCookies = function(cookies) {
|
|
|
300
306
|
|
|
301
307
|
this._setCookie(Request.cookie(cookie), !!(cookieName.match(/^steamMachineAuth/) || cookieName.match(/Secure$/)));
|
|
302
308
|
});
|
|
309
|
+
|
|
310
|
+
// The account we're logged in as might have changed, so verify that our mobile access token (if any) is still valid
|
|
311
|
+
// for this account.
|
|
312
|
+
this._verifyMobileAccessToken();
|
|
303
313
|
};
|
|
304
314
|
|
|
305
315
|
SteamCommunity.prototype.getSessionID = function(host = "http://steamcommunity.com") {
|