c# - 通过 Azure Functions 托管标识进行身份验证
问题描述
我想从其他函数调用一个天蓝色函数。要完成这项工作,我有以下代码:
public static class Function1
{
[FunctionName("Function1")]
public static void Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
ILogger log)
{
Uri m;
string t;
var data = new
{
name = "master"
};
string result = string.Empty;
var askForlicenseURL = "https://<myFunctionname>/api/HttpTrigger_StartOrchestrator";
var content = new StringContent(data.ToString(), Encoding.UTF8, "application/json");
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("x-functions-key", "Md5xxxxxxxxxxxxxxxxxxxxx0ij5A==");
using (HttpResponseMessage response = client.PostAsync(askForlicenseURL, content).Result)
using (HttpContent respContent = response.Content)
{
// ... Read the response as a string.
var tr = respContent.ReadAsStringAsync().Result;
// ... deserialize the response, we know it has a 'result' field
dynamic azureResponse = JsonConvert.DeserializeObject(tr);
// ... read the data we want
result = azureResponse.statusQueryGetUri;
var Header = response.Headers.Location;
}
}
}
在 Azure Function key 的 sted 中,我想使用系统分配managed Identity
的 . (调用者的管理身份被授权为目标 azure 函数中的贡献者,并且我知道我可以使用 Durable Function,但在这种情况下我不想使用它:)
解决方案
它不使用托管标识
谢谢您沉默发表您的评论作为帮助其他社区成员的答案。
““使用代码进行身份验证”部分基本上是您需要查看的地方。实际上,当您使用 MSI 时,它会容易得多,因为您可以直接使用令牌并且可以使用它来进行调用。但第一个重要的一块是在其他功能上启用 AAD 身份验证”。
请参阅 so 线程以获取更多信息How to call another function with in an Azure function。
推荐阅读
- nativescript - 在 RadListView 中,如何删除项目列之间的额外空间?
- aws-sdk - 在 aws SageMaker 容器中设置环境变量(带上您自己的容器)
- hilbert-curve - 如果希尔伯特曲线四叉树有效,为什么要转换为 S2 单元 ID?
- scala - Scala:将映射的java列表转换为scala映射
- python - 使用列表检查按钮状态(tkinter python)
- javascript - 排序时和排序后边距和对齐方式发生变化
- ballerina - Ballerina github4 api 中的“存储库”类型错误中不存在字段“许可证”
- xslt - 使用 xslt 创建 pdf 时,是否可以有一个书签在其所有子部分中保持突出显示
- android - HorizontalScrollView -> LinearLayout -> TextView — 文本更改后滚动条大小不重置
- python-3.x - Pynetdicom3 传输语法