Search code examples
c#azureazure-automation

Error using AutomationManagementClient with CertificateCloudCredentials


I'm trying to start an azure runbook from a MVC app.

var cert = new X509Certificate2(Convert.FromBase64String(ConfigurationManager.AppSettings["CertBase64String"]));
var creds = new CertificateCloudCredentials(ConfigurationManager.AppSettings["SubscriptionId"], cert);

AutomationManagementClient automationManagementClient = new AutomationManagementClient(creds);

var content = automationManagementClient.Runbooks.GetAsync(<Resource group name>, ConfigurationManager.AppSettings["AutomationAccount"], <Runbook name>)

I get this error:

AuthenticationFailed: Authentication failed. The 'Authorization' header is missing.

I got this code from MSDN but I can't seem to make it work. (The certificate is the one downloaded from here ).

I tried using TokenCloudCredentials from a Console app and that seems to work fine but I'm not sure if I can use those in the MVC app.

Any ideas how I should use AutomationManagementClient with certificate credentials? Or how to use TokenCloudCredentials in the web app?


Solution

  • The Automation SDK you are attempting to use uses Azure Resource Manager APIs, which do not support management certificate-based authentication. You will need to authenticate via TokenCloudCredentials. The documentation that shows management certificate support is incorrect and we will update it shortly.