如何在http触发器azure函数应用中添加自定义启动类 [英] How to add custom startup class in http trigger azure function app

查看:23
本文介绍了如何在http触发器azure函数应用中添加自定义启动类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Azure http 触发器功能应用程序不附带启动.我想实现 azure AD 身份验证,它添加了 Microsoft.AspNetCore.BuilderUseAuthentication 方法来验证令牌并对用户进行身份验证.

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.

目前Http触发器直接命中Run方法,应该有一些中间件逻辑来添加服务和配置

Currently Http trigger is hitting the Run method directly.There should be some middle ware logic to add servies and configurations

创业班

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();
}

在 Authorize 属性下面发布实现应该验证令牌并允许/拒绝用户访问.

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");
       }
   }

请帮忙.

推荐答案

Azure 函数默认没有 Startup 类.您可以使用 IWebJobStartup 添加服务,但不能添加自定义中间件.

Azure function by default don't have a Startup class. You can add services using an IWebJobStartup, but you cannot add custom middleware.

这篇关于如何在http触发器azure函数应用中添加自定义启动类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆