2020-04-05 09:48:38 +08:00
|
|
|
// If you aren't running this script inside of the repository, replace the following line with:
|
|
|
|
// const SteamCommunity = require('steamcommunity');
|
|
|
|
const SteamCommunity = require('../index.js');
|
|
|
|
const ReadLine = require('readline');
|
|
|
|
const FS = require('fs');
|
|
|
|
|
|
|
|
const EResult = SteamCommunity.EResult;
|
|
|
|
|
|
|
|
let community = new SteamCommunity();
|
|
|
|
let rl = ReadLine.createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout
|
2015-12-13 07:41:10 +08:00
|
|
|
});
|
|
|
|
|
2020-04-05 09:48:38 +08:00
|
|
|
rl.question('Username: ', (accountName) => {
|
|
|
|
rl.question('Password: ', (password) => {
|
2015-12-13 07:41:10 +08:00
|
|
|
doLogin(accountName, password);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-19 11:33:30 +08:00
|
|
|
function doLogin(accountName, password, authCode, captcha) {
|
2015-12-13 07:41:10 +08:00
|
|
|
community.login({
|
2020-04-05 09:48:38 +08:00
|
|
|
accountName: accountName,
|
|
|
|
password: password,
|
|
|
|
authCode: authCode,
|
|
|
|
captcha: captcha
|
|
|
|
}, (err, sessionID, cookies, steamguard) => {
|
|
|
|
if (err) {
|
|
|
|
if (err.message == 'SteamGuardMobile') {
|
|
|
|
console.log('This account already has two-factor authentication enabled.');
|
2015-12-13 07:41:10 +08:00
|
|
|
process.exit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-05 09:48:38 +08:00
|
|
|
if (err.message == 'SteamGuard') {
|
|
|
|
console.log(`An email has been sent to your address at ${err.emaildomain}`);
|
|
|
|
rl.question('Steam Guard Code: ', (code) => {
|
2015-12-13 07:41:10 +08:00
|
|
|
doLogin(accountName, password, code);
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-05 09:48:38 +08:00
|
|
|
if (err.message == 'CAPTCHA') {
|
2016-03-19 11:33:30 +08:00
|
|
|
console.log(err.captchaurl);
|
2020-04-05 09:48:38 +08:00
|
|
|
rl.question('CAPTCHA: ', (captchaInput) => {
|
2016-03-19 11:33:30 +08:00
|
|
|
doLogin(accountName, password, authCode, captchaInput);
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-13 07:41:10 +08:00
|
|
|
console.log(err);
|
|
|
|
process.exit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-05 09:48:38 +08:00
|
|
|
console.log('Logged on!');
|
2015-12-13 07:41:10 +08:00
|
|
|
|
2023-06-15 08:52:12 +08:00
|
|
|
if (community.mobileAccessToken) {
|
|
|
|
// If we already have a mobile access token, we don't need to prompt for one.
|
|
|
|
doSetup();
|
|
|
|
return;
|
|
|
|
}
|
2015-12-13 07:41:10 +08:00
|
|
|
|
2023-06-15 08:52:12 +08:00
|
|
|
console.log('You need to provide a mobile app access token to continue.');
|
|
|
|
console.log('You can generate one using steam-session (https://www.npmjs.com/package/steam-session).');
|
|
|
|
console.log('The access token needs to be generated using EAuthTokenPlatformType.MobileApp.');
|
|
|
|
console.log('Make sure you provide an *ACCESS* token, not a refresh token.');
|
|
|
|
|
|
|
|
rl.question('Access Token: ', (accessToken) => {
|
|
|
|
community.setMobileAppAccessToken(accessToken);
|
|
|
|
doSetup();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function doSetup() {
|
|
|
|
community.enableTwoFactor((err, response) => {
|
|
|
|
if (err) {
|
|
|
|
if (err.eresult == EResult.Fail) {
|
|
|
|
console.log('Error: Failed to enable two-factor authentication. Do you have a phone number attached to your account?');
|
2015-12-13 07:41:10 +08:00
|
|
|
process.exit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-15 08:52:12 +08:00
|
|
|
if (err.eresult == EResult.RateLimitExceeded) {
|
|
|
|
console.log('Error: RateLimitExceeded. Try again later.');
|
2015-12-13 07:41:10 +08:00
|
|
|
process.exit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-15 08:52:12 +08:00
|
|
|
console.log(err);
|
|
|
|
process.exit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.status != EResult.OK) {
|
|
|
|
console.log(`Error: Status ${response.status}`);
|
|
|
|
process.exit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let filename = `twofactor_${community.steamID.getSteamID64()}.json`;
|
|
|
|
console.log(`Writing secrets to ${filename}`);
|
|
|
|
console.log(`Revocation code: ${response.revocation_code}`);
|
|
|
|
FS.writeFileSync(filename, JSON.stringify(response, null, '\t'));
|
2015-12-13 07:41:10 +08:00
|
|
|
|
2023-06-15 08:52:12 +08:00
|
|
|
promptActivationCode(response);
|
2015-12-13 07:41:10 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function promptActivationCode(response) {
|
2020-04-05 09:48:38 +08:00
|
|
|
rl.question('SMS Code: ', (smsCode) => {
|
|
|
|
community.finalizeTwoFactor(response.shared_secret, smsCode, (err) => {
|
|
|
|
if (err) {
|
|
|
|
if (err.message == 'Invalid activation code') {
|
2015-12-13 07:41:10 +08:00
|
|
|
console.log(err);
|
|
|
|
promptActivationCode(response);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
} else {
|
2020-04-05 09:48:38 +08:00
|
|
|
console.log('Two-factor authentication enabled!');
|
2015-12-13 07:41:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
process.exit();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|