Select Page

In this  Azure REST API post, I will show you how to create an App Registration for Microsoft Azure SDK for .NET.

Azure SDK for .NET allows us to manage Azure programmatically using .NET libraries. Using the SDK, we can create and manage any Azure resource.

The Azure SDK for .NET has more than 200 libraries for almost any Azure service, which allows us to create programs with a small footprint.

To connect to Azure using .NET, we can use the following methods:

  • Azure CLI or Azure PowerShell
  • App Registration
  • Managed identity

In this post, we will show you how to connect using an App Registration because this is how most applications will be used when not in the development stage.

Create an App Registration for Microsoft Azure REST API

To create an App Registration that can access Azure resources, we must use the following Azure CLI command to create a service principal with RBAC permissions.

Start with login into Azure CLI using:

And run the command below to create the service principal account.

Note: In the above example, I’m giving the service account contributor access at my subscription level.

The command output will return an App ID, Display name, Password and the tenant ID. Note down the values, as we will need them soon.

Use App Registration with Azure SDK for .NET

To connect successfully to Azure using the newly created App Registration, we need to use environment variables that the SDK will use to authenticate.

On your server, VS Code or the environment your app will run, add the following environment variables (use the values for the output from the previous section). In the code below, I’m using PowerShell.

List Azure Resource Groups

The following C# Console application will list all the resource groups in the default subscription.

Before you run the code, make sure you add the following libraries to your .csproj file.


Discover more from CPI Consulting Pty Ltd Experts in Cloud, AI and Cybersecurity

Subscribe to get the latest posts sent to your email.