Example #1
0
        /// <summary>
        /// Authenticate with the specified credential.
        /// </summary>
        /// <param name="auth"></param>
        public async void Auth(ConnectCredential credential)
        {
            try
            {
                client = new HttpClient(new HttpBaseProtocolFilter()
                {
                    AllowAutoRedirect = false, ServerCredential = new Windows.Security.Credentials.PasswordCredential()
                    {
                        UserName = credential.UserName, Password = credential.Pin
                    }
                });
                client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36");
                var res = await client.GetAsync(new Uri("http://" + Address + "/default.htm"));

                if (res.IsSuccessStatusCode == true)
                {
                    IsAuthed    = true;
                    IsConnected = true;
                }
                else
                {
                    IsAuthed = false;
                    throw new DeviceConnectionException("Failed to auth.", res.StatusCode);
                }
            }
            catch
            {
                IsAuthed = false;
            }
        }
Example #2
0
        /// <summary>
        /// Authenticate with the specified credential.
        /// </summary>
        /// <param name="auth"></param>
        public async void Auth(ConnectCredential credential)
        {
            try
            {
                var res = await client.PostAsync(new Uri("https://" + Address + $"/api/authorize/pair?pin={credential.Pin}&persistent={credential.Persistent}"), null);

                if (res.IsSuccessStatusCode == true)
                {
                    IsAuthed    = true;
                    IsConnected = true;
                }
                else
                {
                    IsAuthed = false;
                    throw new DeviceConnectionException("Failed to auth.", res.StatusCode);
                }
            }
            catch
            {
                IsAuthed = false;
            }
        }