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); }
public ControlSession(AuthenticatedDevice device) { _device = device; }
public static string GetUrl(this AuthenticatedDevice device) => $"http://{device.Ip}:{device.Port}/{ApiPrefix}/{device.Token}";