-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Currently there are connection:
The connection is made in the following way:
import SteamAuthStandart;
To work with Steam Guard and confirm trades, you need to log in for further actions.
For this we use the class UserLogin
new UserLogin(username:string, password:string)
-
username:string
- Credentials for Steam -
password:string
- Credentials for Steam
//Credentials for Steam
string username = “”;
string password = “”;
//Class initialization
UserLogin login = new UserLogin(username, password);
During authorization on Steam, it may require various account confirmations.
NeedCaptcha
This response sends a link to the captcha image. If this
response
is received, then a unique text is received in CaptchaGID.To get a link use:
APIEndpoints.COMMUNITY_BASE + "/public/captcha.php?gid=" + login.CaptchaGID
Then you need to pass the code from the image to
CaptchaText
login.CaptchaText = captchaText;
captchaText
- сode from the picture
//Attempt to login
LoginResult response = login.DoLogin();
if(response == LoginResult.NeedCaptcha)
{
//Open a web browser to the captcha image
System.Diagnostics.Process.Start(APIEndpoints.COMMUNITY_BASE + "/public/captcha.php?gid=" + login.CaptchaGID);
string captchaText = Console.ReadLine();
login.CaptchaText = captchaText;
response = login.DoLogin();
}
Need2FA
This answer means that Steam Guard is enabled on this account and it asks to code.
Then you need to pass the code from Steam Guard to
TwoFactorCode
//Attempt to login
LoginResult response = login.DoLogin();
if(response == LoginResult.Need2FA)
{
string code = Console.ReadLine();
login.TwoFactorCode = code;
response = login.DoLogin();
}
NeedEmail
This response means that a code was sent to the user's mail to verify the account.
Then you need to pass the code from mail to
EmailCode
//Attempt to login
LoginResult response = login.DoLogin();
if(response == LoginResult.NeedEmail)
{
string code = Console.ReadLine();
login.EmailCode = code;
response = login.DoLogin();
}
Function DoLogin()
which is used in the class UserLogin
returns parameter LoginResult
LoginResult response = login.DoLogin();
LoginResult response = LoginResult.BadCredentials;
while ((response = login.DoLogin()) != LoginResult.LoginOkay)
{
switch (response)
{
case LoginResult.NeedEmail:
Console.WriteLine("Please enter your email code: ");
string code = Console.ReadLine();
login.EmailCode = code;
break;
case LoginResult.NeedCaptcha:
System.Diagnostics.Process.Start(APIEndpoints.COMMUNITY_BASE + "/public/captcha.php?gid=" + login.CaptchaGID);
Console.WriteLine("Please enter captcha text: ");
string captchaText = Console.ReadLine();
login.CaptchaText = captchaText;
break;
case LoginResult.Need2FA:
Console.WriteLine("Please enter your mobile authenticator code: ");
code = Console.ReadLine();
login.TwoFactorCode = code;
break;
}
}
After LoginResult
returned LoginOkay
, you can connect Steam Guard to this account with saving the cipher key.
To do this, you need to use the AuthenticatorLinker
class.
When the class is initialized, the login.Session
argument is passed.
AuthenticatorLinker linker = new AuthenticatorLinker(login.Session);
⚠️ Important!⚠️ To enable Steam Guard,user account must have a phone number associated with it. When adding Steam Guard, an SMS code will be sent to the user's phone.Everything is fine, there is a check on the phone.
During the execution of the function, you will need to save the file with the key and session
In AuthenticatorLinker we need 2 functions:
AddAuthenticator
FinalizeAddAuthenticator
Can be executed after Login
Function linker.AddAuthenticator();
tries to connect Steam Guard to the account if possible.
Function returns AuthenticatorLinker.LinkResult
.
AuthenticatorLinker.LinkResult result = linker.AddAuthenticator();
AuthenticatorLinker linker = new AuthenticatorLinker(login.Session);
var result = linker.AddAuthenticator();
if (result != AuthenticatorLinker.LinkResult.AwaitingFinalization)
Console.WriteLine("Failed to add authenticator: " + result);
If we have the AuthenticatorLinker.LinkResult.AwaitingFinalization
status, this means that a code has been sent to the phone number. But before that, you will need to save a file with these data: linker.LinkedAccount
linker.LinkedAccount
Prepared for JSON serialization. Therefore, I recommend installing the Newtonsoft.Json library
string sgFile = JsonConvert.SerializeObject(linker.LinkedAccount, Formatting.Indented);
//linker.LinkedAccount.AccountName -- return string name account
//File extension optional ".maFile"
string fileName = linker.LinkedAccount.AccountName + ".maFile";
File.WriteAllText(fileName, sgFile);
Can be executed after AddAuthenticator
Function linker.FinalizeAddAuthenticator(smscode);
confirms the account.
The phone number specified in Steam should receive a code that must be specified in smscode
Function returns AuthenticatorLinker.FinalizeResult
.
AuthenticatorLinker.FinalizeResult result = linker.FinalizeAddAuthenticator(smscode);
string smscode = Console.ReadLine();
AuthenticatorLinker.FinalizeResult result = linker.FinalizeAddAuthenticator(smscode);
if (result != AuthenticatorLinker.FinalizeResult.Success)
Console.WriteLine("Unable to finalize authenticator: " + result);
AuthenticatorLinker linker = new AuthenticatorLinker(login.Session);
var result = linker.AddAuthenticator();
if (result != AuthenticatorLinker.LinkResult.AwaitingFinalization)
{
Console.WriteLine("Failed to add authenticator: " + result);
return;
}
string sgFile = JsonConvert.SerializeObject(linker.LinkedAccount, Formatting.Indented);
//linker.LinkedAccount.AccountName -- return string name account
string fileName = linker.LinkedAccount.AccountName + ".maFile";
File.WriteAllText(fileName, sgFile);
string smscode = Console.ReadLine();
AuthenticatorLinker.FinalizeResult resultFinal = linker.FinalizeAddAuthenticator(smscode);
if (resultFinal != AuthenticatorLinker.FinalizeResult.Success)
{
Console.WriteLine("Unable to finalize authenticator: " + result);
return;
}
Console.WriteLine("Account added successfully");