0

I would like to call an azure function from other Function. To do this job I have this code:

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;
            }
        }
    }

In sted of Azure Function key I would like to use system assignedmanaged Identity. (The manaagement Identity of caller is authorized as contributer in target azure function AND I know alternatively I can use Durable Function, but in this case I dont want to use it :)

5
  • 1
    Independent of your question: please do yourself (and mostly your app performance) a favor and read up on Async() processing in C#. You should never do something like .PostAsync().Result Instead make the entire Function async and use await Commented Aug 12, 2021 at 12:44
  • 1
    And here is a pointer how to enable AAD auth and use OAuth tokens to authenticate adatum.no/azure/azure-ad-authentication-in-azure-functions Commented Aug 12, 2021 at 12:47
  • but it doesnt use managed identity Commented Aug 12, 2021 at 13:15
  • 2
    that is correct. But the part "Authenticate with code" is basically where you need to look. Just it is in fact much easier when you are using MSI since you have the token directly available to you and can use that to make the call. but the first important piece is to enable AAD auth on the other Function Commented Aug 12, 2021 at 13:17
  • were u able to find a solution for this problem. I am trying to achieve the same but getting a similar error Commented Mar 6, 2023 at 21:40

1 Answer 1

-1

it doesnt use managed identity

Thank you silent Posting your comment as an answer to help other community members.

"The part "Authenticate with code" is basically where you need to look. Just it is in fact much easier when you are using MSI since you have the token directly available to you and can use that to make the call. but the first important piece is to enable AAD auth on the other Function".

Please refer the so thread for more information How to call another function with in an Azure function .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.