Does azure function support basic authentication?

zmsoft 180 Reputation points
2024-11-11T00:43:23.6733333+00:00

Hi there,

Does azure function support basic authentication? Not use app key in url , use authorization header in request.

Thanks

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,214 questions
{count} votes

2 answers

Sort by: Most helpful
  1. S.Sengupta 20,651 Reputation points MVP
    2024-11-11T01:17:45.8633333+00:00

    Azure Functions supports basic authentication through several methods. For HTTP-triggered functions, one can implement basic authentication (username/password in Authorization header) by creating a custom authentication handler.


  2. Khadeer Ali 1,300 Reputation points Microsoft Vendor
    2024-11-12T08:47:11.97+00:00

    Hi @zmsoft,

    Welcome to the Microsoft Q&A Platform! Thank you for reaching out regarding the basic Authentication for Azure Functions.

    • In your function, the AuthorizationLevel.User allows anonymous access, which is why requests without the Authorization header can still pass through. To ensure that only requests with valid credentials are allowed, change the AuthorizationLevel to Function
        [Function("Function1")]
        public async Task<IActionResult> NewOrder([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
      
      • Ensure that your function app is processing authentication middleware correctly.For that, you should call app.UseAuthentication() in the ConfigureAppConfiguration method.Uncomment and adjust the following:
        .ConfigureAppConfiguration(app =>
        {
            app.UseAuthentication();
        })
      
    • Double-check that the Authorization header is being parsed correctly and handle any errors gracefully.

    If this answers your query, do click accept answer and yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.