question

EmilAlipiev-5934 avatar image
0 Votes"
EmilAlipiev-5934 asked ·

Azure Functions App returning 401 Unauthorized for no reason

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
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SupratimSircar-2521 avatar image
0 Votes"
SupratimSircar-2521 answered ·

Change the AuthorizationLevel to Anonymous.

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







· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

this is not an option for me. As i said authorization works fine in general. Only sometimes there are those exceptions i am seeing in the appcenter. I am not sure why those occur. Azure functions generally behaves strange. it is not only about Authorization. Often throws different http responses like 404.401, 503 etc. although my functions are relatively fast and minimal resource consuming. I have the feeling that Azure functions are not reliable.

0 Votes 0 ·
MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered ·

@EmilAlipiev-5934 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.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.