public async void Start() { ResetView(); Ladebalken.Visible = true; AccessToken = await GetSophosAccessToken(); PartnerAccount = await GetSophosWhoami(AccessToken); PartnerTenants = (await GetSophosPartnerTenants(AccessToken, PartnerAccount.id)).OrderBy(x => x.name).ToList(); ToolStripLabelPartnerName.Text = "Partner-ID: " + PartnerAccount.id; ListBoxKunden.Items.Clear(); foreach (TenantItem einTenant in PartnerTenants) { if (toolStripMenuItemZKunden.Checked == true) { if (einTenant.name.StartsWith("Z - ") || einTenant.name.StartsWith("ZZZ - ")) { } else { ListBoxKunden.Items.Add(einTenant.name); } } else { ListBoxKunden.Items.Add(einTenant.name); } } Ladebalken.Visible = false; }
private static async Task <Whoami> GetSophosWhoami(Token AccessToken) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://api.central.sophos.com"); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + AccessToken.AccessToken); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = client.GetAsync("whoami/v1").Result; response.EnsureSuccessStatusCode(); var jsonContent = await response.Content.ReadAsStringAsync(); Whoami PartnerAccount = JsonConvert.DeserializeObject <Whoami>(jsonContent); return(PartnerAccount); } } catch (Exception e) { MessageBox.Show("Fehler beim WhoAmI-Abruf (Partner): \n" + e.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); return(new Whoami()); } }