Loading...

Communication between APIM and function App as backend

Communication between APIM and function App as backend

Background introduction

When a Function App is added as an API in APIM, there are some authorization details we need to consider while communicating from APIM to the backend function app.

It does not matter what Authorization level (function or anonymous) the function app has configured, APIM will always attach a function host key to the request. The host key is attached to the request as a header. However, we may experiment unauthorized errors even though the function host key is present in the request header.

So, this article is focused on analyzing one of those scenarios when communication between APIM and backend function app is truncated due to unauthorized errors.

 

 

Scenario

Request is going through APIM to backend function app, and we are getting a 401 Unauthorized error.

Note: APIM Subscription required is disabled and function auth level is set to function.

 

Sending the requests from APIM test console.

Didieroc_0-1685049104840.png

 

Same error if we send request from Postman.

Didieroc_1-1685049104848.png

 

We proceed to collect an APIM inspector trace to confirm if the host key is attached to the request.

 

Didieroc_2-1685049104859.png

 

 

Checking the trace, we can confirm the host key is attached to the request as a header. However, is fails with a 401 error.

 

 

Didieroc_3-1685049104867.png

 

If we check the function host keys, we note that the host key attached to the request matches with the apim-didieroc-apim-training host key value. So, why the request is failing even though the host key is the correct one?

 

 

Didieroc_4-1685049104882.png

 

 

Please go to your APIM backends and select the backend object created for function app imported.

 

Didieroc_5-1685049104899.png

 

 

Then, inside the backend object, select Authorization credentials then select Headers. Note that the header that references the host function key stored in a Named value, has the name x-functions-keys.

 

Didieroc_6-1685049104908.png

 

The import function app in APIM process creates that header automatically, but with the header name as x-functions-key. So, if we change that header name that will cause that when the request is sent to the backend function app even though with the correct host key, the function app will not recognize any header name different than x-functions-key.

 

Resolution:

Update the header name, setting it as x-functions-key then save changes.

 

Didieroc_7-1685049104915.png

 

 

Testing after changes

Sending the request again, this time it should succeed.

Didieroc_8-1685049104926.png

 

You can double check if correct header name is present in the APIM inspector trace too.

Didieroc_9-1685049104927.png

 

Published on:

Learn more
Azure PaaS Blog articles
Azure PaaS Blog articles

Azure PaaS Blog articles

Share post:

Related posts

Azure Storage - TLS 1.0 and 1.1 retirement

Overview TLS 1.0 and 1.1 retirement on Azure Storage was previously announced for Nov 1st, 2024, and it was postponed recently to 1 year later...

1 year ago

Efficient Management of Append and Page Blobs Using Azure Storage Actions

  Overview In Azure Storage, Blob Lifecycle Management (BLM) allows you to automate the management of your data based on rules defined by...

1 year ago

[Azure AI Search] Internal Server Error when creating CMK encrypted objects

Scenario Customers follow the Microsoft doc to create CMK encrypted objects (data source, index etc.), but get the 500 Internal Serv...

1 year ago

Optimizing Azure Table Storage: Automated Data Cleanup using a PowerShell script with Azure Automate

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Optimizing Azure Table Storage: Automated Data Clean-up using a PowerShell script with Azure Automat

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Restoring Soft-Deleted Blobs with multithreading in Azure Storage Using C#

Blob soft delete is an essential feature that safeguards your data against accidental deletions or overwrites. By retaining deleted data for a...

1 year ago

Performing simple Azure Table Storage REST API operations using curl command.

The blog provides guidance to perform simple Table Storage REST API operations such as Create table, Delete Table, Insert entity, Delete entit...

1 year ago

Bulk delete all the old jobs from the batch account

Deleting a Job also deletes all Tasks that are part of that Job, and all Job statistics. This also overrides the retention period for Task dat...

1 year ago

Utilizing Azure Storage and Runbooks for scheduled automated backups of Azure SQL Databases

In this article, we are going to provide detailed steps to create a scheduled Azure SQL Database backup to storage account using automation. T...

2 years ago

[Azure Service Bus] JMS messages getting dead-lettered

The article discusses a problem where numerous messages end up in the dead letter queue (DLQ) when the JMS service bus consumer connects to th...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.