Пример #1
0
    private string GetMicrosoftLoginPPFT(int iterationCount = 0) // Going to scrape a page and return an array of strings containing essential values for the login transaction
    {
        HttpWebRequest  request = (HttpWebRequest)HttpWebRequest.Create(urlToScrape);
        HttpWebResponse response;

        try
        {
            response = (HttpWebResponse)request.GetResponse();
        }
        catch (Exception)
        {
            response = null;
        }

        if (response == null && iterationCount < 10)
        {
            return(GetMicrosoftLoginPPFT(iterationCount++));
        }
        else if (iterationCount == 10)
        {
            if (response != null)
            {
                response.Close();
            }
            throw new Exception("Failed to get login parameters after 10 attempts, Microsoft may be down.");
        }

        string responseBody = BetterWebResponse.GetBody(response);

        Regex cookieRegex = new Regex(@"MSPRequ=(.*?);.*,.*MSPOK=(.*?);");

        Match cookieMatch = cookieRegex.Match(response.Headers.Get("Set-Cookie"));

        Cookie mspRequest = new Cookie("MSPRequ", cookieMatch.Groups[1].Value, "/", "login.live.com");

        Cookie mspOk = new Cookie("MSPOK", cookieMatch.Groups[2].Value, cookieMatch.Groups[6].Value, "login.live.com");

        Halo4Api.Cookies.Add(mspRequest);
        Halo4Api.Cookies.Add(mspOk);

        response.Close();

        Regex regex = new Regex("name=\"PPFT\".*?value=\"(.*?)\"");

        Match match = regex.Match(responseBody);

        string PPFT;

        if (match.Success)
        {
            PPFT = match.Groups[1].Value;
        }
        else
        {
            throw new Exception("Failed to get login parameters. Scrape returned no results, Microsoft may have changed their code.");
        }

        return(PPFT);
    }
Пример #2
0
    private WaypointAuthTokenDocument GetWaypointAuthToken(string homepageUrl)
    {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(homepageUrl);

        request.CookieContainer = Halo4Api.Cookies;
        request.UserAgent       = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17";

        WaypointAuthTokenDocument authToken;

        HttpWebResponse response;

        try
        {
            response = (HttpWebResponse)request.GetResponse();

            Regex regex = new Regex("var user.=.*?({.*?});", RegexOptions.Multiline);

            string body = BetterWebResponse.GetBody(response);

            Match match = regex.Match(body);

            if (!match.Success)
            {
                throw new Exception();
            }

            authToken = JsonConvert.DeserializeObject <WaypointAuthTokenDocument>(match.Groups[1].Value);

            Halo4Api.Cookies.Add(response.Cookies);
        }
        catch (Exception)
        {
            throw new Exception("Failed to get Waypoint auth tokens. This is likely a scraping error. Perhaps 343i changed their code layout.");
        }

        response.Close();

        return(authToken);
    }
Пример #3
0
    private WaypointSpartanTokenDocument GetWaypointSpartanToken(WaypointAuthTokenDocument authToken)
    {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(String.Format(waypointRegisterUrl, (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds));

        request.Accept = "application/json";
        request.Headers.Add("Origin", "https://app.halowaypoint.com");
        request.Headers.Add("X-343-Authorization-WLID", "v1=" + authToken.access_token);
        request.CookieContainer = Halo4Api.Cookies;

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        WaypointSpartanTokenDocument spartanToken;

        try
        {
            spartanToken = JsonConvert.DeserializeObject <WaypointSpartanTokenDocument>(BetterWebResponse.GetBody(response));
        }
        catch (Exception)
        {
            throw new Exception("Could not parse Spartan token.");
        }

        Halo4Api.Cookies.Add(response.Cookies);

        return(spartanToken);
    }