在 Azure 门户中通过 'Authentication' blade 保护功能应用程序与在 Startup.cs 中手动保护功能应用程序

Securing Function App via 'Authentication' blade in Azure Portal vs. manually in Startup.cs

我通过修改 Startup.cs 中的配置并调用 Microsoft.Identity.Web 的 [=20] 来保护我的 ASP.NET Core Azure Function App =]AddAuthentiction 和 AddMicrosoftIdentityWebApi 服务上的扩展方法 collection object(类似于 AzureFunctions 示例在 Tests 目录中 Microsoft.Identity.Web 的 GitHub 仓库)。这使我可以使用 Microsoft Identity Platform 从我的 Blazor Server 应用程序安全地调用 Azure Function API。 Azure Functions API 不调用任何下游 api.

此方法非常有效,无需在 Azure 门户中启用 Function App - Setting 下的 Authentication 选项并指定身份提供程序并将其链接到 Azure AD 应用程序注册。

有人知道与 Startup.cs 中的手动配置相比,在 Azure 门户中的 Function App 设置下启用身份验证和添加身份提供者有什么作用吗?如果我理解正确,它会做同样的事情,但在 Startup.cs.

中隐式而不是显式

该选项有时称为“轻松验证”,可启用一个额外的容器(或程序)来验证令牌,因此您不必这样做。请求将首先转到该中间件应用程序,然后,如果验证通过,将转到您的应用程序。

有关详细信息,请参阅文档页面:https://docs.microsoft.com/en-us/azure/app-service/overview-authentication-authorization

该选项对于网络应用程序和函数应用程序是通用的。该代码单独运行,因此它不是您的应用程序中间件链的一部分。