How to get Tags of Azure ResourceManagementClient object

送分小仙女□ 提交于 2019-12-12 08:56:04

问题


I' m trying to get tag list of the resource groups with ResourceManagementClient class.

'Microsoft.Azure.Management.Resources 2.14.1-preview' is added from Package Manager Console

ResourceManagementClient resourceClient = new ResourceManagementClient(new Microsoft.Azure.CertificateCloudCredentials(SubscriptionId, cert));

var tags = resourceClient.Tags.List();

I get this error; AuthenticationFailed: Authentication failed. The 'Authorization' header is not present or provided in an invalid format.

At another sample, the part is working below;

StorageManagementClient storageClient = new StorageManagementClient(new Microsoft.WindowsAzure.CertificateCloudCredentials(SubscriptionId, cert));

There is a difference between these code parts. Microsoft.Azure is used for first sample and Microsoft.WindowsAzure is used for second and the second sample is working.

How can I fix the problem at first sample, can you explain the problem?


回答1:


I have strong belief that ResourceManagementClient can't work with CertificateCloudCredentials, at least that was true for ARM Rest API. I guess you need to first authorize user with login/password as described here and then use obtained token with ResourceManagementClient

Update: First link describes how to register application in AD- can be done from the portal. Next you need to have register in AD a user who will be co-administrator for subscription. After that obtain authorization token with code from second link (using login/password created on prev step) An finally use that token for ResourceManagementClient authorization, something like this(does not compile):

var credentials = new TokenCloudCredentials(<subscrtiption id>, <token>);
new ResourceManagerClient(credentials).DoSomething();


来源:https://stackoverflow.com/questions/28960854/how-to-get-tags-of-azure-resourcemanagementclient-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!