使用 Azure SDK 为 Azure Web 应用上传 SSL 证书文件 (.fpx)

Upload SSL Certificate file (.fpx) for Azure web app using Azure SDK

如何使用 Azure SDK 为 Azure 应用服务上传“.pfx”文件(SSL 证书)?

Azure CLI (Certificates - Create Or Update)中有一个命令,但我想知道Azure SDK中是否有任何功能。

我想(不太确定)是这个

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.appservice.fluent.appservicecertificate.definition.iwithcertificate?view=azure-dotnet

如果要使用c#SDK制作SSL证书,请参考以下步骤

  1. 创建服务主体并将 Contributor 分配给 sp
az login

az ad sp create-for-rbac -n "MyApp" --role contributor \
    --scopes /subscriptions/{SubID} \
    --sdk-auth
  1. 代码
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();