简体   繁体   中英

How to get Tags of Azure ResourceManagementClient object

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?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM