Azure http trigger function apps doesn't comes with a startup. I want to implement azure AD authentication which adds UseAuthentication method of Microsoft.AspNetCore.Builder to validate the token an authenticate the user.
Currently Http trigger is hitting the Run method directly.There should be some middle ware logic to add servies and configurations
Startup Class
public void ConfigureServices(IServiceCollection services)
{ services.AddAuthentication(AzureADDefaults.BearerAuthenticationScheme)
.AddAzureADBearer(options => Configuration.Bind("ConfigName", options));
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger)
{
app.UseAuthentication();
}
post implementation below Authorize attribute should validate the token and allow/deny the user access.
public static class Function1
{
[Authorize]
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
return (ActionResult)new OkObjectResult($"Hello");
}
}
Please help.