首页 > 解决方案 > 通过 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,但在这种情况下我不想使用它:)

标签: c#httpoauthazure-functionsazure-managed-identity

解决方案


它不使用托管标识

谢谢您沉默发表您的评论作为帮助其他社区成员的答案。

““使用代码进行身份验证”部分基本上是您需要查看的地方。实际上,当您使用 MSI 时,它会容易得多,因为您可以直接使用令牌并且可以使用它来进行调用。但第一个重要的一块是在其他功能上启用 AAD 身份验证”。

请参阅 so 线程以获取更多信息How to call another function with in an Azure function


推荐阅读