首页 > 解决方案 > GCP API Gateway / yaml / 安全定义无法正常工作

问题描述

下面是我在 GCP API Gateway 中用作网关配置文件的 yaml。他们的简短版本是它忽略了安全定义。我可以在没有安全/标头信息的情况下调用 API,并且可以找到它。我尝试了几种不同的工具来确保某处没有缓存变量。

`# openapi2-functions.yaml
swagger: '2.0'
info:
  title: Title API
  description: Front end the an API
  version: 1.0.0
schemes:
  - https
produces:
  - application/json
paths:
  /whocantell:
    post:
      summary: mMy API
      operationId: dl
      x-google-backend:
        address: https://someone.somewhere.whoknows
      security:
        - api_key: []
      responses:
        '200':
          description: A successful response
          schema:
            type: string
securityDefinitions:
  api_key:
    type: "apiKey"
    name: "key"
    in: "header"

标签: apirestsecuritygoogle-cloud-platformyaml

解决方案


使用 API Gateway(与 Cloud Endpoint ESPv2 一样,因为 API Gateway 是它的托管版本)。为什么我要说这个?因为约束和限制在大多数情况下是相同的。

如果您查看文档,您会发现,迷失在其中,如果您想在标题中添加您的安全密钥,您需要命名它x-api-key


推荐阅读