【发布时间】:2019-01-31 16:13:59
【问题描述】:
我有两个 Azure 函数应用,都在同一个 Azure 订阅中。我可以检索其中一个的密钥,但不能检索另一个。据我所知,这两个功能应用程序之间没有区别。
我正在使用这个 Powershell 代码:
function GetHostKey
{
param($webAppName, $resourceGroupName)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-Host "Getting master key from $webAppName"
$xml = [xml](Get-AzureRmWebAppPublishingProfile -Name $webAppName -ResourceGroupName $resourceGroupName -Format WebDeploy -OutputFile null)
$msdeployUsername = $xml.SelectNodes("//publishProfile[@publishMethod=`"MSDeploy`"]/@userName").value
$msdeployPassword = $xml.SelectNodes("//publishProfile[@publishMethod=`"MSDeploy`"]/@userPWD").value
$apiBaseUrl = "https://$webAppName.scm.azurewebsites.net/api"
$siteBaseUrl = "https://$webAppName.azurewebsites.net"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $msdeployUsername,$msdeployPassword)))
$jwt = Invoke-RestMethod -Uri "$apiBaseUrl/functions/admin/token" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET
$uri = "$siteBaseUrl/admin/host/systemkeys/_master"
$response = Invoke-RestMethod -Uri $uri -Headers @{Authorization=("Bearer {0}" -f $jwt)} -Method GET
return $response.value
}
对 $siteBaseUrl/admin/host/systemkeys/_master 的调用返回一个函数应用的预期 json,但另一个返回登录屏幕。
【问题讨论】:
-
你可以试试这个代码:stackoverflow.com/questions/46521356/…
-
嗨 Anass,谢谢,但我的代码也遇到了同样的问题!
-
你可以尝试获取默认密钥而不是主密钥
标签: azure authentication azure-active-directory azure-functions