How to proxy requests to the Azure Function?

krishna572 886 Reputation points
2023-02-15T03:40:29.28+00:00

Can we use authorization and authentication in Azure Function .NET Solution with the below code:

For authorization:

[Authorize] keyword (Microsoft.AspNetCore.Authorization)

For Authentication:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) (Microsoft.AspNetCore.Authentication.JwtBearer)

I'm thinking to use the controller in the Main Project where I have Azure Functions and .NET Core Project in the same local path, for proxying the requests to handle by Azure Functions so that can have the common symmetric key for calling the Function APIs?

Is this the right approach or any changes required?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,578 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,803 questions
{count} votes

Accepted answer
  1. Mike Urnun 9,856 Reputation points Microsoft Employee
    2023-02-22T05:26:20.5933333+00:00

    Hello @krishna572 Note that Azure Functions doesn't implement MVC pattern like ASP.NET Core does. If you meant to have both Azure Functions and ASP.NET Core projects under a same solution and leverage the Authentication/Authorization features in ASP.NET Core project (via a Controller) for your Azure Functions project, that won't be possible because projects under a solution in Visual Studio is only a logical grouping of related projects; they don't share same functionalities, dependencies among each other.

    You can still use the same Authentication/Authorization features (of Microsoft.AspNetCore namespace) in Azure Functions though. Please refer to the following blog post: Microsoft.Identity.Web and Azure Functions

    Here's an official sample: https://github.com/AzureAD/microsoft-identity-web/tree/master/tests/DevApps/AzureFunctions

    Additionally, if you still need to run another ASP.NET Core app alongside Azure Functions app but also want a way to handle Authentication/Authorization for both of them from in a centralized manner, you might want to consider placing API Management in front of them:

    I hope this helps, please let me know if you have any questions.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.