Exemplo n.º 1
0
        public async Task <AuthenticatedDevice> Authenticate(Device device, string userAssignedName)
        {
            if (!_devicesToAuthenticate.Contains(device))
            {
                throw new Exception("Can't authenticate device from a different session!");
            }

            var post = await ApiCalls.HttpClient.PostAsync($"http://{device.Ip}:{device.Port}/{ApiCalls.ApiPrefix}/new", new StringContent(""));

            var responseBody = await post.Content.ReadAsStringAsync();

            if (!post.IsSuccessStatusCode)
            {
                throw new Exception($"Authentication failed: {responseBody}");
            }

            var response = JsonConvert.DeserializeObject <AddUserResponse>(responseBody);

            var authenticatedDevice = new AuthenticatedDevice(device.Ip, device.Port, device.Id, device.Firmware, device.Model,
                                                              device.DisplayName, userAssignedName, response.auth_token);

            _authenticatedDevices.Add(authenticatedDevice);

            _devicesToAuthenticate.Remove(device);

            return(authenticatedDevice);
        }
Exemplo n.º 2
0
 public ControlSession(AuthenticatedDevice device)
 {
     _device = device;
 }
Exemplo n.º 3
0
 public static string GetUrl(this AuthenticatedDevice device) => $"http://{device.Ip}:{device.Port}/{ApiPrefix}/{device.Token}";