Azure http 触发函数应用程序不附带启动。我想实现 azure AD 身份验证,它添加了Microsoft.AspNetCore.Builder的UseAuthentication方法来验证令牌并对用户进行身份验证。
目前Http触发器是直接命中Run方法的。应该有一些中间件逻辑来添加服务和配置
创业班
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 应该验证令牌并允许/拒绝用户访问。
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");
}
}
请帮忙。