将 Open API 3.0 导入 Amazon API 网关 - 强制性 API 密钥

Importing Open API 3.0 to the Amazon API Gateway - mandatory API Key

我完成了 OpenAPI 3.0 扩展 here but I could not find an example how to enforce using api keys on method. Basically I'd like to mirror what is shown here (in section "Require API key on a method") 的大部分(全部?)文档,但使用了 OpenAPI .yaml 文件(将其导入到API 网关)。

有什么想法吗?

This example of Cognito 在某处有一个简短的 type: "apiKey" 但我不确定这是否与我的问题有关。

Helen 所述,API 密钥配置为 OpenAPI 安全方案,而不是 AWS 扩展。

对于 Open API 3.0,请在根级别尝试以下配置。

components:
  securitySchemes:
    ApiKeyAuth:        # arbitrary name for the security scheme
      type: apiKey
      in: header       
      name: x-api-key  # name of the header, query parameter or cookie

然后在路径方法级别的根应用以下配置

security:
  - ApiKeyAuth: []

在此处查看更多信息:https://swagger.io/docs/specification/authentication/api-keys/