【问题标题】:How to authenticate an Azure EventGrid API Connection using a script?如何使用脚本对 Azure EventGrid API 连接进行身份验证?
【发布时间】:2019-02-25 22:40:43
【问题描述】:

我正在使用 ARM 模板创建 EventGrid API 连接。它已成功创建,但是,我仍然需要通过 Azure 门户手动对其进行身份验证。

这是我的 ARM 模板:

    "resources": [
    {
        "type": "Microsoft.Web/connections",
        "apiVersion": "2016-06-01",
        "name": "[parameters('azureEventGridConnectionAPIName')]",
        "location": "[resourceGroup().location]",
        "properties": {
            "api": {
                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/', 'azureeventgrid')]"
            },
            "displayName": "[parameters('azureEventGridConnectionAPIName')]"
        },
        "dependsOn": []
    }
]
  1. 我是否遗漏了模板中负责立即验证连接的内容?

  2. 有没有办法使用 Azure PowerShell 来验证该连接,以便我可以自动化该过程?

【问题讨论】:

  • 您是否使用服务主体进行身份验证?

标签: azure azure-powershell arm-template azureportal azure-eventgrid


【解决方案1】:

我是否遗漏了模板中负责立即验证连接的内容?

是的,我们可以在部署期间创建服务主体身份验证。以下是演示代码。

"resources": [
    {
      "type": "Microsoft.Web/connections",
      "apiVersion": "2016-06-01",
      "name": "[parameters('azureEventGridConnectionAPIName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "api": {
          "id": "[concat('/subscriptions/subscriptionId', '/providers/Microsoft.Web/locations/', 'eastasia', '/managedApis/', 'azureeventgrid')]"

        },
        "parameterValues": {
          "token:clientId": "[parameters('clientId')]",
          "token:clientSecret": "[parameters('clientSecret')]",
          "token:TenantId": "[parameters('TenantId')]",
          "token:grantType": "[parameters('grantType')]"
        },
        "displayName": "[parameters('azureEventGridConnectionAPIName')]"

      },
      "dependsOn": []
    }
  ]

Parameters.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "azureEventGridConnectionAPIName": {
      "value": "azureEventGridConnectionAPIName"
    },
    "clientId": {
      "value": "clientId"
    },
    "clientSecret": {
      "value": "secret key"
    },
    "TenantId": {
      "value": "tenant id"
    },
    "grantType": {
      "value": "client_credentials"
    }
  }
}

【讨论】:

  • clientId 是 Azure AD 应用程序 ID。 secret 是应用程序的密钥。更多信息请参考create service principal。我们可以将角色分配给应用程序,然后服务主体将获得操作 Azure 资源的权限。
  • 是的,你可以这样做。如果你想操作 Azure 资源,别忘了给 Azure AD 应用程序分配角色。
  • OAuth2 RFC 要求 /token 端点的`grant_type` URL 参数用于交换真实令牌的授权。如需更多信息,请参阅此SO thread。在我的情况下,使用 clientid 和 secert。所以grantType 是client_credentials。您还可以从document 获得更多信息。
  • 如果有用,请标记为答案。如果您有任何其他问题,欢迎发布新的 SO 线程。
  • I see that a blob storage connector has different parameterValues. 是的,不同的连接器有不同的参数值。
猜你喜欢
  • 2018-11-01
  • 2017-04-08
  • 2021-01-16
  • 1970-01-01
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 2015-07-27
  • 2018-01-04
相关资源
最近更新 更多