Azure 函数授权

Fou*_*der 2 azure azure-functions

我正在将 WebApi 转换为 Azure Function 应用程序。它使用标头中的 SecurityToken 进行身份验证。使用 api,我放入了一个属性来调用身份验证逻辑,但这在 Azure 函数中不起作用。

[ApiAuthentication()]
    [FunctionName("GetConfig")]
    public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get")]HttpRequestMessage req, TraceWriter log)
    {
Run Code Online (Sandbox Code Playgroud)

}

有没有办法让这个工作,或者有更好的方法?

Mik*_*e S 6

ASP.Net WebAPI 属性在 Azure Functions 中不起作用(它们是两个独立的框架,虽然 AF 目前是在 WebAPI 之上实现的,但它并没有将其暴露给表面)。你有一些选择:

  1. 您还可以使用函数过滤器(尽管它们比 ASP.Net 过滤器更受限制)。有关更多文档,请参阅https://github.com/Azure/azure-webjobs-sdk/wiki/Function-Filters
  2. 函数(如常规 Azure 网站)支持与 EasyAuth 集成。在这种情况下,您可以在门户中配置身份验证,系统(通过 IIS 模块)将为您处理身份验证。这是一个关于如何做到这一点的教程:http : //markheath.net/post/secure-azure-functions-app-easy-auth-adb2c