我正在使用 Azure Functions 发送电子邮件SendGrid 绑定 https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-sendgrid。作为该电子邮件内容的一部分,我想包含一个指向其中一个的链接HTTP 方法 https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook在 Azure Functions 实例中了解更多信息。我所有的 HTTP 函数都受到保护AuthorizationLevel.Function
.
我见过一个解决方案在 PowerShell 中从 ARM 和 Kudu 中抓取密钥 https://stackoverflow.com/a/50264228/4062072 (and this one https://stackoverflow.com/a/46436102/4062072)和一个解决方案仅使用 ARM 输出按键 https://stackoverflow.com/a/44117841/4062072,但这些都依赖于我的 Azure Functions 所不具备的功能:对 ARM(Azure 资源管理)API 的权限。
我还找到了Azure Functions 主机的密钥管理 API https://github.com/Azure/azure-functions-host/wiki/Key-management-API这完全按照我想要的本地方式工作,但我不知道如何通过401 Unauthorized
部署 Azure Functions 后。我可以手动通过它_master
功能键,但后来我又不知道如何在运行时获取该键。
问题是:是否可以在运行时从 Azure Function Host 以某种方式获取 Azure Function 的密钥?我非常希望不需要 ARM 权限来执行此操作。
尝试以下两个步骤:
-
获取主机主密钥:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourcegroupName}/providers/Microsoft.Web/sites/{functionApp}/functions/admin/masterkey?api-version=2016-08-01
-
获取功能键:
GET https://{functionApp}.azurewebsites.net/admin/functions/{functionName}/keys?code={masterKeyFromStep1}
步骤 2 的响应:
{
"keys": [
{
"name": "default",
"value": "xxxxxxxxxxxxxxxxxxxxxx"
}
],
"links": [
{
"rel": "self",
"href": "https://myFncApp.azurewebsites.net/admin/functions/myFunction/keys"
}
]
}
Update:
请注意,步骤 1 需要以下格式的授权标头:
Authorization: Bearer bearerToken
其中 bearerToken 字符串可以从 Azure Active Directory (AAD) 获取,请参阅示例的以下代码片段:
private string AccessToken(string clientID)
{
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
authContext = new AuthenticationContext("https://login.windows.net/common/oauth2/authorize", TokenCache.DefaultShared);
var ar = authContext.AcquireTokenAsync("https://management.azure.com/", clientID, new Uri(redirectUri), new PlatformParameters(PromptBehavior.SelectAccount)).Result;
return ar.AccessToken;
}
请注意,clientID是您在 AAD 中注册的具有 API 访问权限的应用程序的 quidWindows Azure 服务管理 API.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)