How to authenticate an Azure EventGrid API Connection using a script?

房东的猫 提交于 2020-05-28 06:12:48

问题


I am creating an EventGrid API Connection using an ARM Template. It gets created successfully, however, i still have to authenticate it by hand via Azure Portal.

Here is my ARM Template:

    "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. Am i missing something in the template that is responsible for authenticating the Connection right away?

  2. Is there a way to authenticate that connection using for example Azure PowerShell so i can automate that process?


回答1:


Am i missing something in the template that is responsible for authenticating the Connection right away?

Yes, we could create a service principal authentication during deploy. Following is the demo code.

"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"
    }
  }
}


来源:https://stackoverflow.com/questions/52445105/how-to-authenticate-an-azure-eventgrid-api-connection-using-a-script

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