0
votes

How can I upload a ".pfx" file (SSL Certificate) for an Azure app service using Azure SDK?

There is a command in Azure CLI (Certificates - Create Or Update), but I would like to know if there are any features in Azure SDK.

2

2 Answers

1
votes

If you want to use c# SDK to create SSL certificate, please refer to the following stpes

  1. Create a service principal and assign Contributor to the sp
az login

az ad sp create-for-rbac -n "MyApp" --role contributor \
    --scopes /subscriptions/{SubID} \
    --sdk-auth
  1. Code
string clientId = "<sp appid>";
            string clientSecret = "<sp password>";
            string tenantDomain = "<sp tenant>";
            string subscription = "";
            var creds= SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantDomain, AzureEnvironment.AzureGlobalCloud);

            var azure= Azure.Configure()
                .WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
                .Authenticate(creds)
                .WithSubscription(subscription);

           var res= azure.AppServices.AppServiceCertificates.Define("test")
                .WithRegion(Region.AsiaEast)
                .WithExistingResourceGroup("<group name>")
                .WithPfxFile(@"<pfx file path>")
                .WithPfxPassword("password")
                .Create();

enter image description here