示例#1
0
    private async void GetToken_Click(object sender, RoutedEventArgs e)
    {
        HttpResponseHeaderCollection respHeaders = await ContactApple(AuthenticationCode.Text);

        ContactsBlock.Text += "CONTACT LINK: " + contactLink + "\n";
        ContactsBlock.Text += authToken + "\n";
        ContactsBlock.Text += authUser + "\n";
    }
示例#2
0
    private async Task <HttpResponseHeaderCollection> ContactApple(String authentication = "")
    {
        // The apple id and the password
        String appleId  = "AppleID";
        String password = "******" + authentication;
        // https://stackoverflow.com/questions/31457068/get-icloud-contact-list-in-c-sharp?noredirect=1&lq=1
        // Post request will have this in the content
        String            data    = "{\"apple_id\":" + appleId + ", \"password\":" + password + ", \"extended_login\":true}";
        HttpStringContent content = new HttpStringContent(data, UnicodeEncoding.Utf8);
        // The URI to get the tokens from:
        Uri requestUri = new Uri("https://setup.icloud.com/setup/ws/1/accountLogin");
        // Create an instance of the HttpClient (Windows.Web.Http)
        HttpClient client = new HttpClient();

        // Add Origin = https://www.icloud.com in the header.
        client.DefaultRequestHeaders.Add("Origin", "https://www.icloud.com");
        // Post request and read response as JSON object (NewtonSoft)
        HttpResponseMessage hrm = await client.PostAsync(requestUri, content);

        JObject resp = JObject.Parse(await hrm.Content.ReadAsStringAsync());

        // Get the URL to the contacts
        contactLink = (String)resp["webservices"]["contacts"]["url"];
        // Read the headers for AUTH-TOKEN and AUTH-USER Cookies,
        HttpResponseHeaderCollection headers = hrm.Headers;

        if (headers.ContainsKey("Set-Cookie"))
        {
            String   cookie     = headers["Set-Cookie"];
            char[]   separators = { ';', ',' };
            String[] tokens     = cookie.Split(separators);
            foreach (String token in tokens)
            {
                int length = token.Length;
                if (token.Contains("X-APPLE-WEBAUTH-TOKEN"))
                {
                    authToken = token;
                }
                if (token.Contains("X-APPLE-WEBAUTH-USER"))
                {
                    authUser = token;
                }
            }
        }
        return(headers);
    }
示例#3
0
        private void SetResponseHeaders(HttpResponseHeaderCollection headers)
        {
            if (responseHeaders == null)
            {
                responseHeaders = new Dictionary <String, String>();
            }
            else
            {
                responseHeaders.Clear();
            }

            foreach (var key in headers.Keys)
            {
                String properties = "";
                foreach (var s in headers[key])
                {
                    properties += s;
                }
                responseHeaders.Add(new KeyValuePair <string, string>(key, properties));
            }
        }
示例#4
0
        private async Task HandleQueueMessage(HttpResponseHeaderCollection headers, IHttpContent content)
        {
            string brokerPropertiesSource;

            if (!headers.TryGetValue("BrokerProperties", out brokerPropertiesSource))
            {
                Log.Warning("Received Azure queue message without broker properties.");
                return;
            }

            string bodySource = await content.ReadAsStringAsync();

            if (string.IsNullOrEmpty(bodySource))
            {
                Log.Warning("Received Azure queue message with empty body.");
                return;
            }

            JsonObject brokerProperties;

            if (!JsonObject.TryParse(brokerPropertiesSource, out brokerProperties))
            {
                Log.Warning("Received Azure queue message with invalid broker properties.");
                return;
            }

            JsonObject body;

            if (!JsonObject.TryParse(bodySource, out body))
            {
                Log.Warning("Received Azure queue message with not supported body (JSON expected).");
                return;
            }

            Log.Verbose("Received valid Azure queue message.");
            MessageReceived?.Invoke(this, new MessageReceivedEventArgs(brokerProperties, body));
        }
示例#5
0
        private async Task HandleQueueMessage(HttpResponseHeaderCollection headers, IHttpContent content)
        {
            string brokerPropertiesSource;

            if (!headers.TryGetValue("BrokerProperties", out brokerPropertiesSource))
            {
                _log.Warning("Received Azure queue message without broker properties.");
                return;
            }

            var bodySource = await content.ReadAsStringAsync();

            if (string.IsNullOrEmpty(bodySource))
            {
                _log.Warning("Received Azure queue message with empty body.");
                return;
            }

            var brokerProperties = JObject.Parse(brokerPropertiesSource);
            var body             = JObject.Parse(bodySource);

            _log.Verbose("Received valid Azure queue message.");
            MessageReceived?.Invoke(this, new MessageReceivedEventArgs(brokerProperties, body));
        }
        /// <summary>
        /// Check HTTP response headers for tile availability, e.g. X-VE-Tile-Info=no-tile
        /// </summary>
        public static bool IsTileAvailable(HttpResponseHeaderCollection responseHeaders)
        {
            string tileInfo;

            return(!responseHeaders.TryGetValue("X-VE-Tile-Info", out tileInfo) || tileInfo != "no-tile");
        }
 public XmlRequestResult()
 {
     uri             = null;
     responseHeaders = null;
 }
        private async Task HandleQueueMessage(HttpResponseHeaderCollection headers, IHttpContent content)
        {
            string brokerPropertiesSource;
            if (!headers.TryGetValue("BrokerProperties", out brokerPropertiesSource))
            {
                Log.Warning("Received Azure queue message without broker properties.");
                return;
            }
            
            var bodySource = await content.ReadAsStringAsync();
            if (string.IsNullOrEmpty(bodySource))
            {
                Log.Warning("Received Azure queue message with empty body.");
                return;
            }

            var brokerProperties = JObject.Parse(brokerPropertiesSource);
            var body = JObject.Parse(bodySource);

            Log.Verbose("Received valid Azure queue message.");
            MessageReceived?.Invoke(this, new MessageReceivedEventArgs(brokerProperties, body));
        }
 internal HttpResponse()
 {
     Headers = new HttpResponseHeaderCollection();
 }
 private static bool ImageAvailable(HttpResponseHeaderCollection responseHeaders)
 {
     return(!responseHeaders.TryGetValue("X-VE-Tile-Info", out string tileInfo) || tileInfo != "no-tile");
 }
示例#11
0
        private void SetResponseHeaders(HttpResponseHeaderCollection headers)
        {
            if (responseHeaders == null)
            {
                responseHeaders = new Dictionary<String, String>();
            }
            else
            {
                responseHeaders.Clear();
            }

            foreach (var key in headers.Keys)
            {
                String properties = "";
                foreach (var s in headers[key])
                {
                    properties += s;
                }
                responseHeaders.Add(new KeyValuePair<string, string>(key, properties));
            }
        }