Skip to content

Instantly share code, notes, and snippets.

@scholtzm
Last active September 23, 2017 13:42
Show Gist options
  • Save scholtzm/354b35db333df64cb520 to your computer and use it in GitHub Desktop.
Save scholtzm/354b35db333df64cb520 to your computer and use it in GitHub Desktop.
[Enable 2FA on your Steam account] #steam

Simple script to enable 2FA on your Steam acocunt

  1. Add a valid phone number to your Steam account via store.steampowered.com account settings panel.
  2. Copy this code from this gist into a enable-2fa.js file and install the dependencies listed at the top.
  3. Start with VAPOR_ADMIN=7657xxx VAPOR_USER=username VAPOR_PASS=password node enable-2fa.js.
  4. Send chat message enable to your bot to enable 2FA.
  5. Wait for the response from Steam servers. Full response which will include your shared_secret and identity_secret will be printed to console as well as saved to a file.
  6. You will receive a text message.
  7. Send chat message confirm CODE to your bot.
  8. You will see a confirmation in the console. You can now press Ctrl+C to kill the script.
var vapor = require('vapor');
var winston = require('vapor-winston-logger');
var SteamUser = require('steam-user');
var SteamID = require('steamid');
var bot = vapor();
const config = {
username: process.env.VAPOR_USER,
password: process.env.VAPOR_PASS,
admins: [ process.env.VAPOR_ADMIN ]
};
bot.init(config);
bot.use(winston, {
fileLevel: 'debug'
});
bot.use(vapor.plugins.fs);
bot.use(vapor.plugins.declineFriendRequests);
bot.use(vapor.plugins.essentials);
bot.use(vapor.plugins.stdinSteamGuard);
bot.use({
name: 'enable-2fa',
plugin: function(API) {
var enableRegex = /^enable$/;
var confirmRegex = /^confirm ([a-zA-Z0-9]+)$/;
var Steam = API.getSteam();
var client = API.getClient();
var utils = API.getUtils();
var log = API.getLogger();
var fileName = API.getConfig().username + '.2fa.json';
var steamUser;
var twoFactorResponse;
API.registerHandler({
emitter: 'vapor',
event: 'ready'
}, function() {
// wait couple seconds otherwise SteamUser goes bananas
setTimeout(function() {
steamUser = new SteamUser(client, {
autoRelogin: false,
promptSteamGuardCode: false
});
// this is derpy
steamUser.steamID = new SteamID(client.steamID);
log.info('SteamUser is ready.');
}, 5000);
});
API.registerHandler({
emitter: 'steamFriends',
event: 'friendMsg'
}, function(user, message, type) {
if(type === Steam.EChatEntryType.ChatMsg) {
if(utils.isAdmin(user)) {
if(enableRegex.test(message)) {
steamUser.enableTwoFactor(function(response) {
log.info('enableTwoFactor response:');
log.info(response);
twoFactorResponse = response;
API.emitEvent('writeFile', fileName, JSON.stringify(response, null, 2), function(error) {
if(error) {
log.error(error);
} else {
log.info('Response has been saved. Waiting for finalization.');
}
});
});
return;
}
if(confirmRegex.test(message)) {
var match = confirmRegex.exec(message);
var code = match[1];
log.info('Using code: %s', code);
steamUser.finalizeTwoFactor(twoFactorResponse.shared_secret, code, function(error) {
if(error) {
log.error(error);
} else {
log.info('2FA has been enabled successfully. You can press Ctrl+C to quit.');
}
});
return;
}
}
}
});
}
});
bot.connect();
process.on('SIGINT', function() {
bot.disconnect();
setTimeout(process.exit, 1000, 0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment