【发布时间】:2021-11-07 04:56:52
【问题描述】:
我正在尝试从订阅中获取应用服务列表,以便我可以过滤暂存站点并使用 Azure SDK 将其删除。我遇到了未正确验证或无法查看订阅中的任何资源的问题。
我在订阅中拥有“所有者”角色,因此我应该可以完全访问订阅及其资源,但是在尝试遵循 Microsoft 的身份验证文档时 (https://docs.microsoft.com/en-us/dotnet/azure/sdk/authentication) 我似乎找不到在订阅级别进行身份验证的方法。
这是我的代码:
var azurecreds = SdkContext.AzureCredentialsFactory
.FromServicePrincipal(
"???", //client ID
"???", //client secret
"have this", //tenant ID
AzureEnvironment.AzureGlobalCloud);
var azure = Azure
.Configure()
.Authenticate(azurecreds)
.WithSubscription("have this"); //subscription ID
//attempts with hard-coded values but not working
var appServicePlans = azure.AppServices.AppServicePlans.List();
var appServicePlans2 = azure.WebApps.List();
var appServicePlans2 = azure.AppServices.AppServicePlans.ListByResourceGroup("Staging");
【问题讨论】:
标签: c# azure sdk subscription