/// <summary> /// Link a mobile authenticator to bot account, using SteamTradeOffersBot as the authenticator. /// Called from bot manager console. Usage: "exec [index] linkauth" /// If successful, 2FA will be required upon the next login. /// Use "exec [index] getauth" if you need to get a Steam Guard code for the account. /// To deactivate the authenticator, use "exec [index] unlinkauth". /// </summary> void LinkMobileAuth() { new Thread(() => { var login = new SteamAuth.UserLogin(logOnDetails.Username, logOnDetails.Password); var loginResult = login.DoLogin(); if (loginResult == SteamAuth.LoginResult.NeedEmail) { while (loginResult == SteamAuth.LoginResult.NeedEmail) { Log.Interface("Enter Steam Guard code from email (type \"input [index] [code]\"):"); var emailCode = WaitForInput(); login.EmailCode = emailCode; loginResult = login.DoLogin(); } } if (loginResult == SteamAuth.LoginResult.LoginOkay) { Log.Info("Linking mobile authenticator..."); var authLinker = new SteamAuth.AuthenticatorLinker(login.Session); var addAuthResult = authLinker.AddAuthenticator(); if (addAuthResult == SteamAuth.AuthenticatorLinker.LinkResult.MustProvidePhoneNumber) { while (addAuthResult == SteamAuth.AuthenticatorLinker.LinkResult.MustProvidePhoneNumber) { Log.Interface("Enter phone number with country code, e.g. +1XXXXXXXXXXX (type \"input [index] [number]\"):"); var phoneNumber = WaitForInput(); authLinker.PhoneNumber = phoneNumber; addAuthResult = authLinker.AddAuthenticator(); } } if (addAuthResult == SteamAuth.AuthenticatorLinker.LinkResult.AwaitingFinalization) { SteamGuardAccount = authLinker.LinkedAccount; try { var authFile = Path.Combine("authfiles", String.Format("{0}.auth", logOnDetails.Username)); Directory.CreateDirectory(Path.Combine(System.Windows.Forms.Application.StartupPath, "authfiles")); File.WriteAllText(authFile, Newtonsoft.Json.JsonConvert.SerializeObject(SteamGuardAccount)); Log.Interface("Enter SMS code (type \"input [index] [code]\"):"); var smsCode = WaitForInput(); var authResult = authLinker.FinalizeAddAuthenticator(smsCode); if (authResult == SteamAuth.AuthenticatorLinker.FinalizeResult.Success) { Log.Success("Linked authenticator."); } else { Log.Error("Error linking authenticator: " + authResult); } } catch (IOException) { Log.Error("Failed to save auth file. Aborting authentication."); } } else { Log.Error("Error adding authenticator: " + addAuthResult); } } else { if (loginResult == SteamAuth.LoginResult.Need2FA) { Log.Error("Mobile authenticator has already been linked!"); } else { Log.Error("Error performing mobile login: " + loginResult); } } }).Start(); }
/// <summary> /// Link a mobile authenticator to bot account, using SteamTradeOffersBot as the authenticator. /// Called from bot manager console. Usage: "exec [index] linkauth" /// If successful, 2FA will be required upon the next login. /// Use "exec [index] getauth" if you need to get a Steam Guard code for the account. /// To deactivate the authenticator, use "exec [index] unlinkauth". /// </summary> void LinkMobileAuth() { new Thread(() => { var login = new SteamAuth.UserLogin(logOnDetails.Username, logOnDetails.Password); var loginResult = login.DoLogin(); if (loginResult == SteamAuth.LoginResult.NeedEmail) { while (loginResult == SteamAuth.LoginResult.NeedEmail) { Log.Interface("Enter Steam Guard code from email (type \"input [index] [code]\"):"); var emailCode = WaitForInput(); login.EmailCode = emailCode; loginResult = login.DoLogin(); } } if (loginResult == SteamAuth.LoginResult.LoginOkay) { Log.Info("Linking mobile authenticator..."); var authLinker = new SteamAuth.AuthenticatorLinker(login.Session); var addAuthResult = authLinker.AddAuthenticator(); if (addAuthResult == SteamAuth.AuthenticatorLinker.LinkResult.MustProvidePhoneNumber) { while (addAuthResult == SteamAuth.AuthenticatorLinker.LinkResult.MustProvidePhoneNumber) { Log.Interface("Enter phone number with country code, e.g. +1XXXXXXXXXXX (type \"input [index] [number]\"):"); var phoneNumber = WaitForInput(); authLinker.PhoneNumber = phoneNumber; addAuthResult = authLinker.AddAuthenticator(); } } if (addAuthResult == SteamAuth.AuthenticatorLinker.LinkResult.AwaitingFinalization) { SteamGuardAccount = authLinker.LinkedAccount; try { var authFile = Path.Combine("authfiles", String.Format("{0}.auth", logOnDetails.Username)); Directory.CreateDirectory(Path.Combine(System.Windows.Forms.Application.StartupPath, "authfiles")); File.WriteAllText(authFile, Newtonsoft.Json.JsonConvert.SerializeObject(SteamGuardAccount)); Log.Interface("Enter SMS code (type \"input [index] [code]\"):"); var smsCode = WaitForInput(); var authResult = authLinker.FinalizeAddAuthenticator(smsCode); if (authResult == SteamAuth.AuthenticatorLinker.FinalizeResult.Success) { Log.Success("Linked authenticator."); } else { Log.Error("Error linking authenticator: " + authResult); } } catch (IOException) { Log.Error("Failed to save auth file. Aborting authentication."); } } else { Log.Error("Error adding authenticator: " + addAuthResult); } } else { if (loginResult == SteamAuth.LoginResult.Need2FA) { Log.Error("Mobile authenticator has already been linked!"); } else { Log.Error("Error performing mobile login: " + loginResult); } } }).Start(); }