public async Task <Profile> GetInternal(string pat) { using (var vsspsHttpClient = new HttpClient()) { var authByteArray = Encoding.ASCII.GetBytes($"username:{pat}"); vsspsHttpClient.BaseAddress = new Uri("https://app.vssps.visualstudio.com/"); vsspsHttpClient.DefaultRequestHeaders.Clear(); vsspsHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authByteArray)); var profileContent = await JsonBase.Get(vsspsHttpClient, "_apis/profile/profiles/me?api-version=5.1"); var profile = JsonBase.FromJson <Profile>(profileContent); return(profile); } }
public async Task <OrganizationList> ReadOrganizations(string PAT) { Console.WriteLine("Reading Organizations"); var organizationList = new OrganizationList(); var authByteArray = Encoding.ASCII.GetBytes($"username:{PAT}"); using (HttpClient vsspsHttpClient = new HttpClient()) { vsspsHttpClient.BaseAddress = new Uri("https://vssps.dev.azure.com"); vsspsHttpClient.DefaultRequestHeaders.Clear(); vsspsHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authByteArray)); var profile = await GetInternal(PAT); var organizationListContent = await JsonBase.Get(vsspsHttpClient, $"_apis/accounts?memberId={profile.Id}&api-version=5.1"); organizationList = JsonBase.FromJson <OrganizationList>(organizationListContent); } return(organizationList); }