private bool SendMultiConfirmationAjax(Confirmation[] confs, string op)
        {
            const string Url = ApiEndpoints.CommunityBase + "/mobileconf/multiajaxop";

            var query = "op=" + op + "&" + this.GenerateConfirmationQueryParams(op);

            foreach (var conf in confs)
            {
                query += "&cid[]=" + conf.ID + "&ck[]=" + conf.Key;
            }

            var cookies = new CookieContainer();

            this.Session.AddCookies(cookies);
            var referer = this.GenerateConfirmationURL();

            var response = SteamWeb.Request(Url, "POST", query, cookies, referer: referer, proxy: this.Proxy);

            if (response == null)
            {
                return(false);
            }

            var confResponse = JsonConvert.DeserializeObject <SendConfirmationResponse>(response);

            return(confResponse.Success);
        }
        private bool SendConfirmationAjax(Confirmation conf, string op)
        {
            var url         = ApiEndpoints.CommunityBase + "/mobileconf/ajaxop";
            var queryString = "?op=" + op + "&";

            queryString += this.GenerateConfirmationQueryParams(op);
            queryString += "&cid=" + conf.ID + "&ck=" + conf.Key;
            url         += queryString;

            var cookies = new CookieContainer();

            this.Session.AddCookies(cookies);
            var referer = this.GenerateConfirmationURL();

            var response = SteamWeb.Request(url, "GET", string.Empty, cookies, null, referer, proxy: this.Proxy);

            if (response == null)
            {
                return(false);
            }

            var confResponse = JsonConvert.DeserializeObject <SendConfirmationResponse>(response);

            return(confResponse.Success);
        }
        public Confirmation[] FetchConfirmations()
        {
            var url = this.GenerateConfirmationURL();

            var cookies = new CookieContainer();

            this.Session.AddCookies(cookies);

            var response = SteamWeb.Request(url, "GET", string.Empty, cookies, proxy: this.Proxy);

            var confRegex = new Regex(
                "<div class=\"mobileconf_list_entry\" id=\"conf[0-9]+\" data-confid=\"(\\d+)\" data-key=\"(\\d+)\" data-type=\"(\\d+)\" data-creator=\"(\\d+)\"");

            if (response == null || !confRegex.IsMatch(response))
            {
                if (response != null && response.Contains(
                        "It looks like your Steam Guard Mobile Authenticator is providing incorrect Steam Guard codes"))
                {
                    throw new SteamException("Invalid authenticator");
                }

                if (response == null || !response.Contains("<div>Nothing to confirm</div>"))
                {
                    throw new SteamException("Error on confirmation fetch! Steam response is empty");
                }

                return(new Confirmation[0]);
            }

            var confirmations = confRegex.Matches(response);

            var ret = new List <Confirmation>();

            foreach (Match confirmation in confirmations)
            {
                if (confirmation.Groups.Count != 5)
                {
                    continue;
                }

                if (!ulong.TryParse(confirmation.Groups[1].Value, out var confID) ||
                    !ulong.TryParse(confirmation.Groups[2].Value, out var confKey) ||
                    !int.TryParse(confirmation.Groups[3].Value, out var confType) || !ulong.TryParse(
                        confirmation.Groups[4].Value,
                        out var confCreator))
                {
                    continue;
                }

                ret.Add(new Confirmation(confID, confKey, confType, confCreator));
            }

            return(ret.ToArray());
        }
示例#4
0
 public static void AlignTime()
 {
     while (_aligned == false)
     {
         try
         {
             var response = SteamWeb.Request(ApiEndpoints.TwoFactorTimeQuery, "POST", dataString: null);
             var query    = JsonConvert.DeserializeObject <TimeQuery>(response);
             _timeDifference = (int)(query.Response.ServerTime - Util.GetSystemUnixTime());
             _aligned        = true;
         }
         catch (Exception ex)
         {
             Logger.Log.Error($"Error on steam time align - {ex.Message}.", ex);
         }
     }
 }
        /// <summary>
        /// Refreshes the Steam session. Necessary to perform confirmations if your session has expired or changed.
        /// </summary>
        /// <returns></returns>
        public bool RefreshSession()
        {
            var postData = new NameValueCollection {
                { "access_token", this.Session.OAuthToken }
            };

            string response;

            try
            {
                response = SteamWeb.Request(ApiEndpoints.MobileAuthGetWgToken, "POST", postData, proxy: this.Proxy);
            }
            catch (WebException)
            {
                return(false);
            }

            if (response == null)
            {
                return(false);
            }

            try
            {
                var refreshResponse = JsonConvert.DeserializeObject <RefreshSessionDataResponse>(response);
                if (refreshResponse?.Response == null || string.IsNullOrEmpty(refreshResponse.Response.Token))
                {
                    return(false);
                }

                var token       = this.Session.SteamID + "%7C%7C" + refreshResponse.Response.Token;
                var 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)
        {
            var url         = ApiEndpoints.CommunityBase + "/mobileconf/details/" + conf.ID + "?";
            var queryString = this.GenerateConfirmationQueryParams("details");

            url += queryString;

            var cookies = new CookieContainer();

            this.Session.AddCookies(cookies);
            var referer = this.GenerateConfirmationURL();

            var response = SteamWeb.Request(url, "GET", string.Empty, cookies, null, proxy: this.Proxy, referer: referer);

            if (string.IsNullOrEmpty(response))
            {
                return(null);
            }

            var confResponse = JsonConvert.DeserializeObject <ConfirmationDetailsResponse>(response);

            return(confResponse);
        }