{
  "properties": {
    "displayName": "Managed identity should be used in your API App",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Use a managed identity for enhanced authentication security",
    "metadata": {
      "version": "2.0.0",
      "category": "App Service"
    },
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "kind",
            "like": "*api"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Web/sites/config",
          "name": "web",
          "existenceCondition": {
            "anyOf": [
                {
                    "field": "Microsoft.Web/sites/config/managedServiceIdentityId",
                    "exists": "true"
                },
                {
                    "field": "Microsoft.Web/sites/config/xmanagedServiceIdentityId",
                    "exists": "true"
                } 
            ]
          }
        }
      }
    }
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/c4d441f8-f9d9-4a9e-9cef-e82117cb3eef",
  "name": "c4d441f8-f9d9-4a9e-9cef-e82117cb3eef"
}