Skip to content

Instantly share code, notes, and snippets.

@explorer14
Created July 2, 2018 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explorer14/a8c72c4fcf688fc8b272c915c22935a3 to your computer and use it in GitHub Desktop.
Save explorer14/a8c72c4fcf688fc8b272c915c22935a3 to your computer and use it in GitHub Desktop.
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