Azure Functions App returning 401 Unauthorized for no reason

Emil Alipiev 271 Reputation points
2021-02-21T01:59:21.41+00:00

I have my azure functions app working fine in general. I enabled function level authorization and already providing x-functions-key with the correct key in the header.
So azure function is consumed by an Android app, in the appcenter logs, i am seeing some logs have

"StatusCode": 401,
"ReasonPhrase": "Unauthorized",

This makes no sense. I have fully logged request and request is just fine when i re-execute it using postman or similar. In the Azure portal under functions availability all green and in the connected Application Insights nothing is reported. Why am i getting this response?

EDIT:

Beside that error there are a few others in the Appcenter diagnostics. 503 and 404 response codes there are also. When i try to find those requests in the Azure portal I have no trace neither in Azure Functions monitoring nor in Application insights. What kind of issue is this?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,297 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Supratim Sircar 186 Reputation points
    2021-02-21T04:49:31.027+00:00

    Change the AuthorizationLevel to Anonymous.

    public static async Task<IActionResult> Run(
                    [HttpTrigger(**AuthorizationLevel.Anonymous**, "get", "post", Route = null)] HttpRequest req,
                    ILogger log){
    
    }
    
    4 people found this answer helpful.

  2. MayankBargali-MSFT 68,641 Reputation points
    2021-02-22T10:00:55.723+00:00

    @Emil Alipiev 401 error shouldn't be observed until and unless the authentication is not passed correctly. As you have confirmed that you are passing the x-functions-key correctly and the same request works from the postman as per your observation. I would like to take a closer look offline at how you are calling the function app.

    For 404 error there might be some calls where the request URL was not correct when called from a different application. 503 error we need to look into more details at the function app end as there could be different reasons for 503 (Service Unavailable) errors.

    0 comments No comments