From ddf02214895d7d026d3fae6133c19fec032dd643 Mon Sep 17 00:00:00 2001 From: Alexander Corn Date: Sat, 2 Apr 2016 16:14:17 -0400 Subject: [PATCH] Added disable_twofactor example --- examples/disable_twofactor.js | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 examples/disable_twofactor.js diff --git a/examples/disable_twofactor.js b/examples/disable_twofactor.js new file mode 100644 index 0000000..6e4f4a2 --- /dev/null +++ b/examples/disable_twofactor.js @@ -0,0 +1,61 @@ +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) { + rl.question("Two-Factor Auth Code: ", function(authCode) { + rl.question("Revocation Code: R", function(rCode) { + doLogin(accountName, password, authCode, "", rCode); + }); + }); + }); +}); + +function doLogin(accountName, password, authCode, captcha, rCode) { + community.login({ + "accountName": accountName, + "password": password, + "twoFactorCode": authCode, + "captcha": captcha + }, function(err, sessionID, cookies, steamguard) { + if(err) { + if(err.message == 'SteamGuard') { + console.log("This account does not have two-factor authentication enabled."); + process.exit(); + return; + } + + if(err.message == 'CAPTCHA') { + console.log(err.captchaurl); + rl.question("CAPTCHA: ", function(captchaInput) { + doLogin(accountName, password, authCode, captchaInput); + }); + + return; + } + + console.log(err); + process.exit(); + return; + } + + console.log("Logged on!"); + community.disableTwoFactor("R" + rCode, function(err) { + if(err) { + console.log(err); + process.exit(); + return; + } + + console.log("Two-factor authentication disabled!"); + process.exit(); + }); + }); +}