ARM模板Web应用程序身份验证设置不起作用

时间:2019-01-28 22:55:20

标签: azure-active-directory azure-web-sites azure-resource-manager

我正在设置站点身份验证设置以使用AAD提供程序。大多数模板都受到尊重。但是,unauthenticatedClientActionallowedAudiences的分配不正确。我观察到“允许匿名”,没有分配“允许的受众”。

这是这些设置的模板段。它嵌套在我的网站模板中的资源下。

root> Microsoft.Web /网站>资源

{
    "type": "config",
    "name": "web",
    "apiVersion": "2016-08-01",
    "location": "[parameters('app-location')]",
    "dependsOn": [
        "[resourceId('Microsoft.Web/sites', variables('web-site-name'))]"
    ],
    "properties": {
        "siteAuthEnabled": true,
        "siteAuthSettings": {
            "enabled": true,
            "unauthenticatedClientAction": "RedirectToLoginPage",
            "tokenStoreEnabled": true,
            "defaultProvider": "AzureActiveDirectory",
            "clientId": "[parameters('web-aad-client-id')]",
            "issuer": "[concat('https://sts.windows.net/', parameters('web-aad-tenant'))]",
            "allowedAudiences": [
                "[concat('https://', variables('web-site-name'), '.azurewebsites.net')]"
            ]
        }
    }
}
  • 模板验证
  • 部署不会输出任何错误

问题:

  1. unauthenticatedClientAction被分配为允许匿名而不是RedirectToLoginPage
  2. allowedAudiences未分配任何站点

什么可能导致这些问题?我可能错过了什么?

2 个答案:

答案 0 :(得分:3)

如@Michael所述,必须将siteAuthSettings对象添加到siteConfig对象中,而不仅仅是在根properties对象下方。

{
    "apiVersion": "2019-08-01",
    "name": "[variables('webAppName')]",
    "type": "Microsoft.Web/sites",
    "kind": "app",
    "location": "[resourceGroup().location]",
    "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('appServiceName'))]"
    ],
    "properties": {
        ...
        "siteConfig": {
            "siteAuthSettings": {
                "enabled": true,
                "unauthenticatedClientAction": "RedirectToLoginPage",
                "tokenStoreEnabled": true,
                "defaultProvider": "AzureActiveDirectory",
                "clientId": "[parameters('clientId')]",
                "issuer": "[concat('https://sts.windows.net/', parameters('tenantId'), '/')]"
            }
        }
    }
}

答案 1 :(得分:2)

与Azure支持的优秀人员一起工作后,我得到了答案。

此子资源不再是有效的解决方案,尽管端点可能仍可以识别其某些字段,但已弃用。

新的解决方案是将siteAuthSettings对象添加到主要的'Microsoft.Web / site'属性中,并且不再需要siteAuthEnabled,因为siteAuthSettings.enable复制了此功能。

更新了ARM模板(为简洁起见,删除了其他设置)

{
    "name": "[variables('app-service-name')]",
    "type": "Microsoft.Web/sites",
    "location": "[parameters('app-location')]",
    "apiVersion": "2016-08-01",
    "dependsOn": [
        "[variables('app-plan-name')]"
    ],
    "properties": {
        //... other app service settings
        "siteAuthSettings": {
            "enabled": true,
            "unauthenticatedClientAction": "RedirectToLoginPage",
            "tokenStoreEnabled": true,
            "defaultProvider": "AzureActiveDirectory",
            "clientId": "[parameters('web-aad-client-id')]",
            "issuer": "[concat('https://sts.windows.net/', parameters('web-aad-tenant'))]",
            "allowedAudiences": [
                "[concat('https://', variables('web-site-name'), '.azurewebsites.net')]"
            ]
        }
    }
}