api - 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"
解决方案
使用 API Gateway(与 Cloud Endpoint ESPv2 一样,因为 API Gateway 是它的托管版本)。为什么我要说这个?因为约束和限制在大多数情况下是相同的。
如果您查看文档,您会发现,迷失在其中,如果您想在标题中添加您的安全密钥,您需要命名它x-api-key
推荐阅读
- javascript - 发布者域验证失败。服务器返回了意外的内容类型标头值
- ruby-on-rails - Rails 安排每日电子邮件任务
- splunk - Splunk如何解决基于扫描历史的扫描问题?
- java - 在 RxJava 中,Emitter 接口和 Observer 接口有什么区别?两者都有相同的方法
- json - ASP.Net Core Put FromBody 请求验证 - json 请求仅包含一个 bool 字段
- r - 在 data.table 中滚动 cumsum
- python - 多个内核大小的 cv2.GaussianBlur
- python - 我无法将 pygame 转换为 exe
- java - 在 Java 中用于存储 100+ 百万个散列项的最佳集合是什么
- javascript - 从 Angular 下载 .doc 文件