");
- if(!tradeOfferIDRegex.IsMatch(confDetails.HTML)) return -1;
- return long.Parse(tradeOfferIDRegex.Match(confDetails.HTML).Groups[1].Value);
- }
-
- public bool AcceptConfirmation(Confirmation conf)
- {
- return _sendConfirmationAjax(conf, "allow");
- }
-
- public bool DenyConfirmation(Confirmation conf)
- {
- return _sendConfirmationAjax(conf, "cancel");
- }
-
- ///
- /// Refreshes the Steam session. Necessary to perform confirmations if your session has expired or changed.
- ///
- ///
- public bool RefreshSession()
- {
- string url = APIEndpoints.MOBILEAUTH_GETWGTOKEN;
- NameValueCollection postData = new NameValueCollection();
- postData.Add("access_token", this.Session.OAuthToken);
-
- string response = SteamWeb.Request(url, "POST", postData);
- if (response == null) return false;
-
- try
- {
- var refreshResponse = JsonConvert.DeserializeObject
(response);
- if (refreshResponse == null || refreshResponse.Response == null || String.IsNullOrEmpty(refreshResponse.Response.Token))
- return false;
-
- string token = this.Session.SteamID + "%7C%7C" + refreshResponse.Response.Token;
- string tokenSecure = this.Session.SteamID + "%7C%7C" + refreshResponse.Response.TokenSecure;
-
- this.Session.SteamLogin = token;
- this.Session.SteamLoginSecure = tokenSecure;
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
-
- ///
- /// Refreshes the Steam session. Necessary to perform confirmations if your session has expired or changed.
- ///
- ///
- public async Task RefreshSessionAsync()
- {
- string url = APIEndpoints.MOBILEAUTH_GETWGTOKEN;
- NameValueCollection postData = new NameValueCollection();
- postData.Add("access_token", this.Session.OAuthToken);
-
- string response = await SteamWeb.RequestAsync(url, "POST", postData);
- if (response == null) return false;
-
- try
- {
- var refreshResponse = JsonConvert.DeserializeObject(response);
- if (refreshResponse == null || refreshResponse.Response == null || String.IsNullOrEmpty(refreshResponse.Response.Token))
- return false;
-
- string token = this.Session.SteamID + "%7C%7C" + refreshResponse.Response.Token;
- string tokenSecure = this.Session.SteamID + "%7C%7C" + refreshResponse.Response.TokenSecure;
-
- this.Session.SteamLogin = token;
- this.Session.SteamLoginSecure = tokenSecure;
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
-
- private ConfirmationDetailsResponse _getConfirmationDetails(Confirmation conf)
- {
- string url = APIEndpoints.COMMUNITY_BASE + "/mobileconf/details/" + conf.ID + "?";
- string queryString = GenerateConfirmationQueryParams("details");
- url += queryString;
-
- CookieContainer cookies = new CookieContainer();
- this.Session.AddCookies(cookies);
- string referer = GenerateConfirmationURL();
-
- string response = SteamWeb.Request(url, "GET", null, cookies, null);
- if (String.IsNullOrEmpty(response)) return null;
-
- var confResponse = JsonConvert.DeserializeObject(response);
- if (confResponse == null) return null;
- return confResponse;
- }
-
- private bool _sendConfirmationAjax(Confirmation conf, string op)
- {
- string url = APIEndpoints.COMMUNITY_BASE + "/mobileconf/ajaxop";
- string queryString = "?op=" + op + "&";
- queryString += GenerateConfirmationQueryParams(op);
- queryString += "&cid=" + conf.ID + "&ck=" + conf.Key;
- url += queryString;
-
- CookieContainer cookies = new CookieContainer();
- this.Session.AddCookies(cookies);
- string referer = GenerateConfirmationURL();
-
- string response = SteamWeb.Request(url, "GET", null, cookies, null);
- if (response == null) return false;
-
- SendConfirmationResponse confResponse = JsonConvert.DeserializeObject(response);
- return confResponse.Success;
- }
-
- public string GenerateConfirmationURL(string tag = "conf")
- {
- string endpoint = APIEndpoints.COMMUNITY_BASE + "/mobileconf/conf?";
- string queryString = GenerateConfirmationQueryParams(tag);
- return endpoint + queryString;
- }
-
- public string GenerateConfirmationQueryParams(string tag)
- {
- if (String.IsNullOrEmpty(DeviceID))
- throw new ArgumentException("Device ID is not present");
-
- long time = TimeAligner.GetSteamTime();
- return "p=" + this.DeviceID + "&a=" + this.Session.SteamID.ToString() + "&k=" + _generateConfirmationHashForTime(time, tag) + "&t=" + time + "&m=android&tag=" + tag;
- }
-
- private string _generateConfirmationHashForTime(long time, string tag)
- {
- byte[] decode = Convert.FromBase64String(this.IdentitySecret);
- int n2 = 8;
- if (tag != null)
- {
- if (tag.Length > 32)
- {
- n2 = 8 + 32;
- }
- else
- {
- n2 = 8 + tag.Length;
- }
- }
- byte[] array = new byte[n2];
- int n3 = 8;
- while (true)
- {
- int n4 = n3 - 1;
- if (n3 <= 0)
- {
- break;
- }
- array[n4] = (byte)time;
- time >>= 8;
- n3 = n4;
- }
- if (tag != null)
- {
- Array.Copy(Encoding.UTF8.GetBytes(tag), 0, array, 8, n2 - 8);
- }
-
- try
- {
- HMACSHA1 hmacGenerator = new HMACSHA1();
- hmacGenerator.Key = decode;
- byte[] hashedData = hmacGenerator.ComputeHash(array);
- string encodedData = Convert.ToBase64String(hashedData, Base64FormattingOptions.None);
- string hash = WebUtility.UrlEncode(encodedData);
- return hash;
- }
- catch (Exception)
- {
- return null; //Fix soon: catch-all is BAD!
- }
- }
-
- //TODO: Determine how to detect an invalid session.
- public class WGTokenInvalidException : Exception
- {
- }
-
- private class RefreshSessionDataResponse
- {
- [JsonProperty("response")]
- public RefreshSessionDataInternalResponse Response { get; set; }
- internal class RefreshSessionDataInternalResponse
- {
- [JsonProperty("token")]
- public string Token { get; set; }
-
- [JsonProperty("token_secure")]
- public string TokenSecure { get; set; }
- }
- }
-
- private class RemoveAuthenticatorResponse
- {
- [JsonProperty("response")]
- public RemoveAuthenticatorInternalResponse Response { get; set; }
-
- internal class RemoveAuthenticatorInternalResponse
- {
- [JsonProperty("success")]
- public bool Success { get; set; }
- }
- }
-
- private class SendConfirmationResponse
- {
- [JsonProperty("success")]
- public bool Success { get; set; }
- }
-
- private class ConfirmationDetailsResponse
- {
- [JsonProperty("success")]
- public bool Success { get; set; }
-
- [JsonProperty("html")]
- public string HTML { get; set; }
- }
- }
+ }
}
diff --git a/SteamAuth/SteamWeb.cs b/SteamAuth/SteamWeb.cs
deleted file mode 100644
index 1b52cf658..000000000
--- a/SteamAuth/SteamWeb.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-using System;
-using System.Collections.Specialized;
-using System.IO;
-using System.Net;
-using System.Threading.Tasks;
-
-namespace SteamAuth
-{
- public class SteamWeb
- {
- ///
- /// Perform a mobile login request
- ///
- /// API url
- /// GET or POST
- /// Name-data pairs
- /// current cookie container
- /// response body
- public static string MobileLoginRequest(string url, string method, NameValueCollection data = null, CookieContainer cookies = null, NameValueCollection headers = null)
- {
- return Request(url, method, data, cookies, headers, APIEndpoints.COMMUNITY_BASE + "/mobilelogin?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client");
- }
-
- public static string Request(string url, string method, NameValueCollection data = null, CookieContainer cookies = null, NameValueCollection headers = null, string referer = APIEndpoints.COMMUNITY_BASE)
- {
- string query = (data == null ? string.Empty : string.Join("&", Array.ConvertAll(data.AllKeys, key => String.Format("{0}={1}", WebUtility.UrlEncode(key), WebUtility.UrlEncode(data[key])))));
- if (method == "GET")
- {
- url += (url.Contains("?") ? "&" : "?") + query;
- }
-
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Method = method;
- request.Accept = "text/javascript, text/html, application/xml, text/xml, */*";
- request.UserAgent = "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";
- request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
- request.Referer = referer;
-
- if (headers != null)
- {
- request.Headers.Add(headers);
- }
-
- if (cookies != null)
- {
- request.CookieContainer = cookies;
- }
-
- if (method == "POST")
- {
- request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
- request.ContentLength = query.Length;
-
- StreamWriter requestStream = new StreamWriter(request.GetRequestStream());
- requestStream.Write(query);
- requestStream.Close();
- }
-
- try
- {
- using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
- {
- if (response.StatusCode != HttpStatusCode.OK)
- {
- return null;
- }
-
- using (StreamReader responseStream = new StreamReader(response.GetResponseStream()))
- {
- string responseData = responseStream.ReadToEnd();
- return responseData;
- }
- }
- }
- catch (WebException)
- {
- return null;
- }
- }
-
- public static async Task RequestAsync(string url, string method, NameValueCollection data = null, CookieContainer cookies = null, NameValueCollection headers = null, string referer = APIEndpoints.COMMUNITY_BASE)
- {
- string query = (data == null ? string.Empty : string.Join("&", Array.ConvertAll(data.AllKeys, key => String.Format("{0}={1}", WebUtility.UrlEncode(key), WebUtility.UrlEncode(data[key])))));
- if (method == "GET")
- {
- url += (url.Contains("?") ? "&" : "?") + query;
- }
-
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Method = method;
- request.Accept = "text/javascript, text/html, application/xml, text/xml, */*";
- request.UserAgent = "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";
- request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
- request.Referer = referer;
-
- if (headers != null)
- {
- request.Headers.Add(headers);
- }
-
- if (cookies != null)
- {
- request.CookieContainer = cookies;
- }
-
- if (method == "POST")
- {
- request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
- request.ContentLength = query.Length;
-
- StreamWriter requestStream = new StreamWriter(request.GetRequestStream());
- requestStream.Write(query);
- requestStream.Close();
- }
-
- try
- {
- using (HttpWebResponse response = (HttpWebResponse) await request.GetResponseAsync()) {
-
- if (response.StatusCode != HttpStatusCode.OK) {
- return null;
- }
-
- using (StreamReader responseStream = new StreamReader(response.GetResponseStream())) {
- string responseData = responseStream.ReadToEnd();
- return responseData;
- }
- }
- }
- catch (WebException)
- {
- return null;
- }
- }
- }
-}
diff --git a/SteamAuth/TimeAligner.cs b/SteamAuth/TimeAligner.cs
deleted file mode 100644
index 11489cedd..000000000
--- a/SteamAuth/TimeAligner.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using System.Net;
-using Newtonsoft.Json;
-
-namespace SteamAuth
-{
- ///
- /// Class to help align system time with the Steam server time. Not super advanced; probably not taking some things into account that it should.
- /// Necessary to generate up-to-date codes. In general, this will have an error of less than a second, assuming Steam is operational.
- ///
- public class TimeAligner
- {
- private static bool _aligned = false;
- private static int _timeDifference = 0;
-
- public static long GetSteamTime()
- {
- if (!TimeAligner._aligned)
- {
- TimeAligner.AlignTime();
- }
- return Util.GetSystemUnixTime() + _timeDifference;
- }
-
- public static async Task GetSteamTimeAsync()
- {
- if (!TimeAligner._aligned)
- {
- await TimeAligner.AlignTimeAsync();
- }
- return Util.GetSystemUnixTime() + _timeDifference;
- }
-
- public static void AlignTime()
- {
- long currentTime = Util.GetSystemUnixTime();
- using (WebClient client = new WebClient())
- {
- try
- {
- string response = client.UploadString(APIEndpoints.TWO_FACTOR_TIME_QUERY, "steamid=0");
- TimeQuery query = JsonConvert.DeserializeObject(response);
- TimeAligner._timeDifference = (int)(query.Response.ServerTime - currentTime);
- TimeAligner._aligned = true;
- }
- catch (WebException)
- {
- return;
- }
- }
- }
-
- public static async Task AlignTimeAsync()
- {
- long currentTime = Util.GetSystemUnixTime();
- WebClient client = new WebClient();
- try
- {
- string response = await client.UploadStringTaskAsync(new Uri(APIEndpoints.TWO_FACTOR_TIME_QUERY), "steamid=0");
- TimeQuery query = JsonConvert.DeserializeObject(response);
- TimeAligner._timeDifference = (int)(query.Response.ServerTime - currentTime);
- TimeAligner._aligned = true;
- }
- catch (WebException)
- {
- return;
- }
- }
-
- internal class TimeQuery
- {
- [JsonProperty("response")]
- internal TimeQueryResponse Response { get; set; }
-
- internal class TimeQueryResponse
- {
- [JsonProperty("server_time")]
- public long ServerTime { get; set; }
- }
-
- }
- }
-}
diff --git a/SteamAuth/UserLogin.cs b/SteamAuth/UserLogin.cs
deleted file mode 100644
index a298d2166..000000000
--- a/SteamAuth/UserLogin.cs
+++ /dev/null
@@ -1,252 +0,0 @@
-using Newtonsoft.Json;
-using System;
-using System.Collections.Specialized;
-using System.Net;
-using System.Security.Cryptography;
-using System.Text;
-
-namespace SteamAuth
-{
- ///
- /// Handles logging the user into the mobile Steam website. Necessary to generate OAuth token and session cookies.
- ///
- public class UserLogin
- {
- public string Username;
- public string Password;
- public ulong SteamID;
-
- public bool RequiresCaptcha;
- public string CaptchaGID = null;
- public string CaptchaText = null;
-
- public bool RequiresEmail;
- public string EmailDomain = null;
- public string EmailCode = null;
-
- public bool Requires2FA;
- public string TwoFactorCode = null;
-
- public SessionData Session = null;
- public bool LoggedIn = false;
-
- private CookieContainer _cookies = new CookieContainer();
-
- public UserLogin(string username, string password)
- {
- this.Username = username;
- this.Password = password;
- }
-
- public LoginResult DoLogin()
- {
- var postData = new NameValueCollection();
- var cookies = _cookies;
- string response = null;
-
- if (cookies.Count == 0)
- {
- //Generate a SessionID
- cookies.Add(new Cookie("mobileClientVersion", "0 (2.1.3)", "/", ".steamcommunity.com"));
- cookies.Add(new Cookie("mobileClient", "android", "/", ".steamcommunity.com"));
- cookies.Add(new Cookie("Steam_Language", "english", "/", ".steamcommunity.com"));
-
- NameValueCollection headers = new NameValueCollection();
- headers.Add("X-Requested-With", "com.valvesoftware.android.steam.community");
-
- SteamWeb.MobileLoginRequest("https://steamcommunity.com/login?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client", "GET", null, cookies, headers);
- }
-
- postData.Add("username", this.Username);
- response = SteamWeb.MobileLoginRequest(APIEndpoints.COMMUNITY_BASE + "/login/getrsakey", "POST", postData, cookies);
- if (response == null || response.Contains("\nAn error occurred while processing your request.")) return LoginResult.GeneralFailure;
-
- var rsaResponse = JsonConvert.DeserializeObject(response);
-
- if (!rsaResponse.Success)
- {
- return LoginResult.BadRSA;
- }
-
- RNGCryptoServiceProvider secureRandom = new RNGCryptoServiceProvider();
- byte[] encryptedPasswordBytes;
- using (var rsaEncryptor = new RSACryptoServiceProvider())
- {
- var passwordBytes = Encoding.ASCII.GetBytes(this.Password);
- var rsaParameters = rsaEncryptor.ExportParameters(false);
- rsaParameters.Exponent = Util.HexStringToByteArray(rsaResponse.Exponent);
- rsaParameters.Modulus = Util.HexStringToByteArray(rsaResponse.Modulus);
- rsaEncryptor.ImportParameters(rsaParameters);
- encryptedPasswordBytes = rsaEncryptor.Encrypt(passwordBytes, false);
- }
-
- string encryptedPassword = Convert.ToBase64String(encryptedPasswordBytes);
-
- postData.Clear();
- postData.Add("username", this.Username);
- postData.Add("password", encryptedPassword);
-
- postData.Add("twofactorcode", this.TwoFactorCode ?? "");
-
- postData.Add("captchagid", this.RequiresCaptcha ? this.CaptchaGID : "-1");
- postData.Add("captcha_text", this.RequiresCaptcha ? this.CaptchaText : "");
-
- postData.Add("emailsteamid", (this.Requires2FA || this.RequiresEmail) ? this.SteamID.ToString() : "");
- postData.Add("emailauth", this.RequiresEmail ? this.EmailCode : "");
-
- postData.Add("rsatimestamp", rsaResponse.Timestamp);
- postData.Add("remember_login", "false");
- postData.Add("oauth_client_id", "DE45CD61");
- postData.Add("oauth_scope", "read_profile write_profile read_client write_client");
- postData.Add("loginfriendlyname", "#login_emailauth_friendlyname_mobile");
- postData.Add("donotcache", Util.GetSystemUnixTime().ToString());
-
- response = SteamWeb.MobileLoginRequest(APIEndpoints.COMMUNITY_BASE + "/login/dologin", "POST", postData, cookies);
- if (response == null) return LoginResult.GeneralFailure;
-
- var loginResponse = JsonConvert.DeserializeObject(response);
-
- if (loginResponse.Message != null && loginResponse.Message.Contains("Incorrect login"))
- {
- return LoginResult.BadCredentials;
- }
-
- if (loginResponse.CaptchaNeeded)
- {
- this.RequiresCaptcha = true;
- this.CaptchaGID = loginResponse.CaptchaGID;
- return LoginResult.NeedCaptcha;
- }
-
- if (loginResponse.EmailAuthNeeded)
- {
- this.RequiresEmail = true;
- this.SteamID = loginResponse.EmailSteamID;
- return LoginResult.NeedEmail;
- }
-
- if (loginResponse.TwoFactorNeeded && !loginResponse.Success)
- {
- this.Requires2FA = true;
- return LoginResult.Need2FA;
- }
-
- if (loginResponse.Message != null && loginResponse.Message.Contains("too many login failures"))
- {
- return LoginResult.TooManyFailedLogins;
- }
-
- if (loginResponse.OAuthData == null || loginResponse.OAuthData.OAuthToken == null || loginResponse.OAuthData.OAuthToken.Length == 0)
- {
- return LoginResult.GeneralFailure;
- }
-
- if (!loginResponse.LoginComplete)
- {
- return LoginResult.BadCredentials;
- }
- else
- {
- var readableCookies = cookies.GetCookies(new Uri("https://steamcommunity.com"));
- var oAuthData = loginResponse.OAuthData;
-
- SessionData session = new SessionData();
- session.OAuthToken = oAuthData.OAuthToken;
- session.SteamID = oAuthData.SteamID;
- session.SteamLogin = session.SteamID + "%7C%7C" + oAuthData.SteamLogin;
- session.SteamLoginSecure = session.SteamID + "%7C%7C" + oAuthData.SteamLoginSecure;
- session.WebCookie = oAuthData.Webcookie;
- session.SessionID = readableCookies["sessionid"].Value;
- this.Session = session;
- this.LoggedIn = true;
- return LoginResult.LoginOkay;
- }
- }
-
- private class LoginResponse
- {
- [JsonProperty("success")]
- public bool Success { get; set; }
-
- [JsonProperty("login_complete")]
- public bool LoginComplete { get; set; }
-
- [JsonProperty("oauth")]
- public string OAuthDataString { get; set; }
-
- public OAuth OAuthData
- {
- get
- {
- return OAuthDataString != null ? JsonConvert.DeserializeObject(OAuthDataString) : null;
- }
- }
-
- [JsonProperty("captcha_needed")]
- public bool CaptchaNeeded { get; set; }
-
- [JsonProperty("captcha_gid")]
- public string CaptchaGID { get; set; }
-
- [JsonProperty("emailsteamid")]
- public ulong EmailSteamID { get; set; }
-
- [JsonProperty("emailauth_needed")]
- public bool EmailAuthNeeded { get; set; }
-
- [JsonProperty("requires_twofactor")]
- public bool TwoFactorNeeded { get; set; }
-
- [JsonProperty("message")]
- public string Message { get; set; }
-
- internal class OAuth
- {
- [JsonProperty("steamid")]
- public ulong SteamID { get; set; }
-
- [JsonProperty("oauth_token")]
- public string OAuthToken { get; set; }
-
- [JsonProperty("wgtoken")]
- public string SteamLogin { get; set; }
-
- [JsonProperty("wgtoken_secure")]
- public string SteamLoginSecure { get; set; }
-
- [JsonProperty("webcookie")]
- public string Webcookie { get; set; }
- }
- }
-
- private class RSAResponse
- {
- [JsonProperty("success")]
- public bool Success { get; set; }
-
- [JsonProperty("publickey_exp")]
- public string Exponent { get; set; }
-
- [JsonProperty("publickey_mod")]
- public string Modulus { get; set; }
-
- [JsonProperty("timestamp")]
- public string Timestamp { get; set; }
-
- [JsonProperty("steamid")]
- public ulong SteamID { get; set; }
- }
- }
-
- public enum LoginResult
- {
- LoginOkay,
- GeneralFailure,
- BadRSA,
- BadCredentials,
- NeedCaptcha,
- Need2FA,
- NeedEmail,
- TooManyFailedLogins,
- }
-}
diff --git a/SteamAuth/Util.cs b/SteamAuth/Util.cs
deleted file mode 100644
index 0574e7d58..000000000
--- a/SteamAuth/Util.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-using System.Net;
-
-namespace SteamAuth
-{
- public class Util
- {
- public static long GetSystemUnixTime()
- {
- return (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
- }
-
- public static byte[] HexStringToByteArray(string hex)
- {
- int hexLen = hex.Length;
- byte[] ret = new byte[hexLen / 2];
- for (int i = 0; i < hexLen; i += 2)
- {
- ret[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
- }
- return ret;
- }
- }
-}