Skip to content

Instantly share code, notes, and snippets.

@buchizo
Created October 14, 2018 18:22
Show Gist options
  • Save buchizo/b732c417812ea7bb3c3789d494aac2c7 to your computer and use it in GitHub Desktop.
Save buchizo/b732c417812ea7bb3c3789d494aac2c7 to your computer and use it in GitHub Desktop.
MSI Sample
using Microsoft.Azure.Management.WebSites;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Rest;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
Task.Run(async () =>
{
try
{
var tokenp = new AzureServiceTokenProvider();
var at = await tokenp.GetAccessTokenAsync("https://management.azure.com/");
var c = new WebSiteManagementClient(new TokenCredentials(at))
{
SubscriptionId = "REPLACE MY SUBSCRIPTION ID"
};
var apps = await c.WebApps.ListAsync();
Console.WriteLine(apps.ToList().First().Name);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}).Wait();
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment