从ARM模板部署Logic App Custom Connector时设置身份验证

时间:2019-07-23 09:53:38

标签: azure arm-template

我正在通过手臂模板部署Logic App自定义连接器。在ARM模板中,类型为Microsoft.Web / customApi。

我们还正在部署连接器(Microsoft.Web / connections)。

这些项部署正常,但基本身份验证参数无法在customApi和连接之间正确链接。

Basic auth missing the username and password display labels

虽然参数的显示名称已反映在连接中,但这似乎一切正常(请注意,密码应该为空,我们使用的测试REST API仅使用用户名):

Connection object showing paramters OK

如果我们将显示名称添加到自定义连接器中,并更新连接,则它将起作用。这是自定义连接器在更新后的样子:

Custom API looking OK after manual change

因此,我们希望仅通过ARM部署来达到这一点,而无需手动步骤。可能吗? Microsoft.Web / customApi的文档没有提供有关您可以提供的connectionParameters的任何详细信息。

customApi的ARM代码段:

 "type": "Microsoft.Web/customApis",
  "name": "[variables('CustomConnectorName')]",
  "apiVersion": "2016-06-01",
  "location": "[variables('resourceGroupLocation')]",
  "tags": {
    "Environment": "[variables('environment')]"
  },
  "scale": null,
  "properties": {
    "capabilities": [
      "gateway"
    ],
    "connectionParameters": {
      "username": {
        "type": "string",
        "uiDefinition": {
          "displayName": "ConnectionUsername",              
          "description": "The UserName for this api",
          "tooltip": "Provide the UserName",
          "constraints": {
            "tabIndex": 2,
            "clearText": true,
            "required": "true"
          }
        }
      },
      "password": {
        "type": "string",
        "uiDefinition": {
          "displayName": "ConnectionPassword",              
          "description": "The Password for this api",
          "tooltip": "Provide the Password",
          "constraints": {
            "tabIndex": 3,
            "clearText": false,
            "required": "false"
          }
        }
      },
      "authType": {
        "type": "string",
        "allowedValues": [
          {
            "value": "basic"
          }
        ],
        "uiDefinition": {
          "displayName": "Authentication Type",
          "description": "Authentication type to connect to your API",
          "tooltip": "Authentication type to connect to your API",
          "constraints": {
            "tabIndex": 1,
            "required": "true",
            "allowedValues": [
              {
                "text": "basic",
                "value": "basic"
              }
            ]
          }
        }
      },
      "gateway": {
        "type": "gatewaySetting",
        "gatewaySettings": {
          "dataSourceType": "CustomConnector",
          "connectionDetails": []
        },
        "uiDefinition": {
          "constraints": {
            "tabIndex": 4,
            "required": "true",
            "capability": [
              "gateway"
            ]
          }
        }
      }
    },

用于连接的ARM代码段:

 "type": "Microsoft.Web/connections",
  "apiVersion": "2016-06-01",
  "location": "[resourceGroup().location]",
  "name": "MyCustomConnector",
  "properties": {
    "api": {
      "id": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',resourceGroup().name,'/providers/Microsoft.Web/customApis/MyCustomConnector')]"
    },
    "displayName": "MyCustomConnector",
    "parameterValues": {
      "username": "[variables('UserName')]",
      "password": "[variables('Password')]",
      "authType": "basic",
      "gateway": {
        "id": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('coreResourceGroupName'),'/providers/Microsoft.Web/connectionGateways/',variables('onPremiseGatewayName'))]"
      }
    }
  }
}

对于任何有关如何使customApi在保存正确参数名称的情况下进行部署以消除手动步骤需求的建议,我将不胜感激。

谢谢

2 个答案:

答案 0 :(得分:0)

在部署自定义连接器时,连接应由用户使用其各自的apikey或连接器正在使用的任何身份验证来创建。

所以我对您的模板做了一些修改,它似乎可以正常工作。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "resources": [
        {
            "type": "Microsoft.Web/customApis",
            "apiVersion": "2016-06-01",
            "name": "Test",
            "location": "[resourceGroup().location]",
            "properties": {
                "capabilities": [
                    "gateway"
                ],
                "connectionParameters": {
                    "username": {
                        "type": "string",
                        "uiDefinition": {
                            "displayName": "ConnectionUsername",
                            "description": "The UserName for this api",
                            "tooltip": "Provide the UserName",
                            "constraints": {
                                "tabIndex": 2,
                                "clearText": true,
                                "required": "true"
                            }
                        }
                    },
                    "password": {
                        "type": "string",
                        "uiDefinition": {
                            "displayName": "ConnectionPassword",
                            "description": "The Password for this api",
                            "tooltip": "Provide the Password",
                            "constraints": {
                                "tabIndex": 3,
                                "clearText": false,
                                "required": "false"
                            }
                        }
                    },
                    "authType": {
                        "type": "string",
                        "allowedValues": [
                            {
                                "value": "basic"
                            }
                        ],
                        "uiDefinition": {
                            "displayName": "Authentication Type",
                            "description": "Authentication type to connect to your API",
                            "tooltip": "Authentication type to connect to your API",
                            "constraints": {
                                "tabIndex": 1,
                                "required": "true",
                                "allowedValues": [
                                    {
                                        "text": "basic",
                                        "value": "basic"
                                    }
                                ]
                            }
                        }
                    },
                    "gateway": {
                        "type": "gatewaySetting",
                        "gatewaySettings": {
                            "dataSourceType": "CustomConnector",
                            "connectionDetails": []
                        },
                        "uiDefinition": {
                            "constraints": {
                                "tabIndex": 4,
                                "required": "true",
                                "capability": [
                                    "gateway"
                                ]
                            }
                        }
                    }
                },
                "backendService": {
                    "serviceUrl": "[concat('https://helloWorld.azurewebsites.net/')]"
                }
            }
        }
    ]
}

当您尝试从LogicApp访问此连接器时,它的外观如下

enter image description here

请注意从[variables('resourceGroupLocation')][resourceGroup().location]的更改,它实际上是内置的Arm模板,您可以访问指向模板的当前资源组的位置。

我还要添加的另一件事是backendService,它将指向您的API URL。

希望这会有所帮助。

答案 1 :(得分:0)

如果使用swagger为API建模,则可以将安全要求定义为swagger的一部分。我使用API​​-Key方法进行基本身份验证,尽管我认为您可能可以使Basic方法按要求工作,但我没有尝试过。 https://swagger.io/docs/specification/2-0/authentication/

这是我在ARM模板中使用的Microsoft.Web / customApis JSON类型上的swagger属性的示例(为简洁起见,将其剪裁)。

        "swagger": {
          "swagger": "2.0",
          "host": "example.sausages.com",
          ...
          "securityDefinitions": {
            "APIKeyHeader": {
              "type": "apiKey",
              "in": "header",
              "name": "Authorization"
            }
          },
          "security": [
            {
              "APIKeyHeader": []
            }
          ],
          "paths": {
            "/sausages": {
              "get": {
                ...
              }
            }
          }
        } 

部署后,可使用自定义连接器的安全性部分以及定义良好的端点。