[英]Unable to upload to Azure BLOB storage via Az Module or Az/CLI
[英]Unable to set unauthenticatedClientAction with Az module or Az/CLI
我设计了一个 PowerShell 脚本,它能够正确配置Function 应用程序的各种设置(包括 CORS 等)。 Function 应用程序有效,可以从 Api 管理服务调用。
当需要配置Azure AD时,我使用Az/CLI来准确复制我使用Portal UI所做的事情(并且我手动设置的内容非常有效)。 但它停止工作,APIM 返回HTTP 状态码 401 (未授权)。
配置 Azure AD 的脚本部分如下:
# $add is a simple class that contains value to be configured
# actually AllowedTokens is always empty
if ($aad) {
'Setting Function App AAD configuration.' | Write-Verbose
$allowedTokens = if ($aad.AllowedTokens) { "--aad-allowed-token-audiences $($aad.AllowedTokens -join ' ')" } else { '' }
"az webapp auth update --name $name --resource-group $group --enabled $($aad.Enabled.ToString().ToLower())" +
" --action LoginWithAzureActiveDirectory --aad-client-id $($aad.ClientId) --aad-client-secret $($aad.ClientSecret)" +
" --token-store true" +
" --aad-token-issuer-url $($aad.TokenIssuerUrl) $allowedTokens" |
Invoke-Expression
'Function App AAD configuration set.' | Write-Verbose
}
第一个奇怪的事情是,如果我禁用身份验证/授权,
我保存设置,启用并再次保存一切开始工作。
所以我重新开始并启动了脚本。 我检查了资源。
az auth show
说unauthenticatedClientAction
设置为RedirectToLoginpage
。
az resource show
说unauthenticatedClientAction
设置为null
。
当我执行上述技巧时:
az auth show
表示unauthenticatedClientAction
设置为AllowAnonymous
。
az resource show
说unauthenticatedClientAction
设置为null
。
所以我认为这是使 Function 应用程序正常工作的重要区别(或者更好的是,这是正确配置它的方法)。
由于我已成功将此方法用于其他设置,因此我尝试使用 Az/CLI 设置此属性:
az resource update --name web --resource-group $group --namespace Microsoft.Web --resource-type config `
--parent "sites/$funcName" --set properties.siteAuthSettings.unauthenticatedClientAction=AllowAnonymous
作为响应返回的 JSON 显示没有任何变化。 检查资源确认它。
还有一件事,当我导出资源组时,我在任何 Function 应用程序模板中都看不到任何unauthenticatedClientAction
。
将unauthenticatedClientAction
设置为AllowAnonymous
的正确方法是什么?
任何帮助将不胜感激!
首先,回答您的问题,将unauthenticatedClientAction
设置为AllowAnonymous
,只需使用
az webapp auth update --name <functionapp-name> --resource-group <group-name> --action AllowAnonymous
实际上,当您在门户中执行此操作时,它会改变
至
这是unauthenticatedClientAction
设置。
那么问题来了,我不确定你是否想用 Azure AD 保护你的 azure function。 因为当您将unauthenticatedClientAction
设置为AllowAnonymous
时,您的 function 将允许匿名请求,因此 Azure AD 身份验证将不会生效。
当需要配置 Azure AD 时,我使用 Az/CLI 来准确复制我使用 Portal UI 所做的事情(并且我手动设置的内容非常有效)。 但它停止工作,APIM 返回 HTTP 状态码 401(未授权)。
Yes, the 401 error represents the Azure AD auth toke effect, if you enable the Azure AD auth(set Log in with Azure Active Directory
), you need to get the access token for your client/user, then use the token to access the function。 (不知道如何在 APIM 中实现它,我不是 APIM 专家:-))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.