Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Task("Get-PublishProfiles")
.IsDependentOn("Publish")
.Does(async ()=>{
Information("Retrieving access token...");
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://login.microsoftonline.com/");
Dictionary<string, string> kvps = new Dictionary<string, string>();
kvps.Add("grant_type", "client_credentials");
kvps.Add("client_id", cakeDeployerClientId);
kvps.Add("client_secret", cakeDeployerClientSecret);
kvps.Add("resource", "https://management.azure.com/");
FormUrlEncodedContent content = new FormUrlEncodedContent(kvps);
var response = await client.PostAsync($"{azureTenantId}/oauth2/token", content);
if (response.IsSuccessStatusCode)
{
dynamic tokenResult = JsonConvert.DeserializeObject(
await response.Content.ReadAsStringAsync());
accessToken = tokenResult.access_token;
if (!string.IsNullOrWhiteSpace(accessToken))
{
Information("Access token retrieved successfully!");
}
}
else
{
Information(response.ReasonPhrase);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment