예제 #1
0
        public bool DeactivateAuthenticator(int scheme = 2)
        {
            var postData = new NameValueCollection();

            postData.Add("steamid", this.Session.SteamID.ToString());
            postData.Add("steamguard_scheme", scheme.ToString());
            postData.Add("revocation_code", this.RevocationCode);
            postData.Add("access_token", this.Session.OAuthToken);

            try
            {
                string response       = SteamWeb.MobileLoginRequest(APIEndpoints.STEAMAPI_BASE + "/ITwoFactorService/RemoveAuthenticator/v0001", "POST", postData);
                var    removeResponse = JsonConvert.DeserializeObject <RemoveAuthenticatorResponse>(response);

                if (removeResponse == null || removeResponse.Response == null || !removeResponse.Response.Success)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #2
0
        private bool _sendMultiConfirmationAjax(Confirmation[] confs, string op)
        {
            string url = APIEndpoints.COMMUNITY_BASE + "/mobileconf/multiajaxop";

            string query = "op=" + op + "&" + GenerateConfirmationQueryParams(op);

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

            CookieContainer cookies = new CookieContainer();

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

            string response = SteamWeb.Request(url, "POST", query, cookies, null);

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

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

            return(confResponse.Success);
        }
예제 #3
0
        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", "", cookies, null);

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

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

            return(confResponse.Success);
        }
예제 #4
0
        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", "", cookies, null);

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

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

            if (confResponse == null)
            {
                return(null);
            }
            return(confResponse);
        }
예제 #5
0
        public async Task <Confirmation[]> FetchConfirmationsAsync()
        {
            string url = this.GenerateConfirmationURL();

            CookieContainer cookies = new CookieContainer();

            this.Session.AddCookies(cookies);

            string response = await SteamWeb.RequestAsync(url, "GET", null, cookies);

            /*So you're going to see this abomination and you're going to be upset.
             * It's understandable. But the thing is, regex for HTML -- while awful -- makes this way faster than parsing a DOM, plus we don't need another library.
             * And because the data is always in the same place and same format... It's not as if we're trying to naturally understand HTML here. Just extract strings.
             * I'm sorry. */

            Regex 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("<div>Nothing to confirm</div>"))
                {
                    throw new WGTokenInvalidException();
                }

                return(new Confirmation[0]);
            }

            MatchCollection confirmations = confRegex.Matches(response);

            List <Confirmation> ret = new List <Confirmation>();

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

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

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

            return(ret.ToArray());
        }
예제 #6
0
        /// <summary>
        /// Refreshes the Steam session. Necessary to perform confirmations if your session has expired or changed.
        /// </summary>
        /// <returns></returns>
        public async Task <bool> RefreshSessionAsync()
        {
            string url = APIEndpoints.MOBILEAUTH_GETWGTOKEN;
            NameValueCollection postData = new NameValueCollection();

            postData.Add("access_token", this.Session.OAuthToken);

            string response = null;

            try
            {
                response = await SteamWeb.RequestAsync(url, "POST", postData);
            }
            catch (WebException)
            {
                return(false);
            }

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

            try
            {
                var refreshResponse = JsonConvert.DeserializeObject <RefreshSessionDataResponse>(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);
            }
        }