Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
.Does(async ()=>{
Information("Retrieving access token...");
using (var client = new HttpClient())
client.BaseAddress = new Uri("");
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", "");
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!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment