当 Key 为 public 时,Azure Function API Key 有什么意义吗?

Is there any point in an Azure Function API Key when the Key is public?

Azure Functions 允许 API 密钥用作授权形式。

API key authorization

By default, an HTTP trigger requires an API key in the HTTP request. So your HTTP request normally looks like the following:

https://<yourapp>.azurewebsites.net/api/<function>?code=<ApiKey>

You can allow anonymous requests, which do not require keys.

在我的例子中,Azure 函数是在网站单页客户端应用程序中使用的,因此 API 密钥对任何调试该应用程序的人都有效地公开可用。

在这种情况下,使用 API 密钥有什么意义吗?

对于意外调用和愚蠢的爬虫仍然有用。对于后者,您应该使用 headers 中的密钥,如下所示:

GET /api/get-issues HTTP/1.1
Host: {funcapp}.azurewebsites.net
User-Agent: ajax-library-of-the-day
x-functions-key: rkW0PqT.....zcUBQ==

如果 user-agent 后端 API 授权是您主要关心的问题,则您需要 OAuth 2.0 隐式流程。

如果您为这些 401 Unauthorized 付费,则无法发表评论。很可能不会,否则这将导致非常昂贵的攻击向量,而您的订阅则处于昂贵的一端。