使用 AzureWebJob 中的 Azure 管理 API
Using Azure Management API from AzureWebJob
我正在开发一个需要 运行 AzureWebJob 的应用程序,以便在将消息放置在 AzureQueue 上时部署站点的新实例。我正在使用 CertificateCloudeCredentials 来验证请求。我正在使用以下代码创建凭据:
var certificateString = "<the certificate string>";
var certificateString = ConfigurationManager.AppSettings["Base64Certificate"];
var certificate = new X509Certificate2(Convert.FromBase64String(certificateString));
var credentials = new CertificateCloudCredentials("67baa805-e391-4e9a-a26e-aa76d33f6475", certificate);
var managementClient = new WebSiteManagementClient(credentials);
在我的开发机器上这工作正常,但是当我在 Azure 上上传 WebJob 时,当我尝试向管理客户端实例发出请求时出现异常。
异常消息说:"Message:ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription."
显然我需要在将 运行 代码的机器上安装证书,但由于这是一个 WebJob 运行ning 在 Azure WebApplication 上,我该如何实现呢?
管理 API 的另一个身份验证选项是使用 TokenCredentials,但我无法在我的本地环境中进行这些操作。我试过本指南无济于事 https://msdn.microsoft.com/en-us/library/dn722415.aspx 。我也怀疑它是否会起作用,因为您需要使用 Azure 帐户登录才能获取令牌。
那么.. ¿如何使用 WebJob 中的管理 API?
我认为令牌凭证是更好的选择。我有一个完整的示例 here,您可以使用它来获取灵感。您将需要设置一个服务主体,您可以通过 Azure 应用设置将其提供给您的应用。
我正在开发一个需要 运行 AzureWebJob 的应用程序,以便在将消息放置在 AzureQueue 上时部署站点的新实例。我正在使用 CertificateCloudeCredentials 来验证请求。我正在使用以下代码创建凭据:
var certificateString = "<the certificate string>";
var certificateString = ConfigurationManager.AppSettings["Base64Certificate"];
var certificate = new X509Certificate2(Convert.FromBase64String(certificateString));
var credentials = new CertificateCloudCredentials("67baa805-e391-4e9a-a26e-aa76d33f6475", certificate);
var managementClient = new WebSiteManagementClient(credentials);
在我的开发机器上这工作正常,但是当我在 Azure 上上传 WebJob 时,当我尝试向管理客户端实例发出请求时出现异常。 异常消息说:"Message:ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription."
显然我需要在将 运行 代码的机器上安装证书,但由于这是一个 WebJob 运行ning 在 Azure WebApplication 上,我该如何实现呢?
管理 API 的另一个身份验证选项是使用 TokenCredentials,但我无法在我的本地环境中进行这些操作。我试过本指南无济于事 https://msdn.microsoft.com/en-us/library/dn722415.aspx 。我也怀疑它是否会起作用,因为您需要使用 Azure 帐户登录才能获取令牌。
那么.. ¿如何使用 WebJob 中的管理 API?
我认为令牌凭证是更好的选择。我有一个完整的示例 here,您可以使用它来获取灵感。您将需要设置一个服务主体,您可以通过 Azure 应用设置将其提供给您的应用。