我已经安装了 nuget Microsoft.Azure.Management.ResourceManager
并具有以下代码来根据资源组名称
获取所有现有资源
var resouceManagementClient = new ResourceManagementClient(credentials) { SubscriptionId = "mySubscriptionId" };
var listResources =
resouceManagementClient.ResourceGroups.ListResources("Demo-ResourceGroup");
我不确定从哪里可以获得credentials
参数值。
I do not have Azure Active Directory access , I think its must , can we bypass azure AD?.
在我的 azure 门户中,我创建了一个资源组 - Demo-ResourceGroup
并创建了许多资源
。
我只想使用 C# 代码列出所有现有资源。
最佳答案
一种方法是从 Azure AD 获取访问 token 并将其传递到 TokenCredentials
类。
var authContext = new AuthenticationContext(string.Format("https://login.windows.net/{0}", tenantId));
var credential = new ClientCredential(applicationId, password);
AuthenticationResult token = authContext.AcquireTokenAsync("https://management.core.windows.net/", credential).Result;
var credentials = new TokenCredentials(token.AccessToken);
用于请求访问 token 的凭据集(在本例中为 clientId/secret)将确定应用程序是否具有枚举资源的适当权限。 This is a good MS docs page on how to register your application with AAD 。上例中,applicationId和password来自AAD中的应用注册
Microsoft has a page describing other ways you can get tokens from AAD .
关于c# - 如何传递凭据以使用 ResourceManagementClient 从 azure 资源组 C# 获取所有资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48241591/