【问题标题】:Cloud endpoints is it possible to protect all API accesses using only a base URL?云端点是否可以仅使用基本 URL 来保护所有 API 访问?
【发布时间】:2020-08-31 06:53:51
【问题描述】:

假设我的 api 位于 domain/_ah/api。我们有 domain/_ah/api/getUser、domain/_ah/api/stuff/getStuff、domain/_ah/api/stuff/moreStuff/postMoreStuff。

是否可以通过仅定义这样的内容来做到这一点?'

  swagger: '2.0'
  info:
    title: "Cloud Endpoints + Cloud Run"
    description: "Sample API on Cloud Endpoints with a Cloud Run backend"
    version: "1.0.0"
  host: "domain"
  schemes:
    - "https"
  produces:
    - "application/json"
  x-google-backend:
    jwt_audience: "audience"
    address: "domain_backend"
    protocol: "h2"
  paths:
    /_ah/api/*:
      get, post, put, etc:
        description: "Protects Base URL"
        operationId: "authInfoFirebase"
        security: 
          - firebase: []

  securityDefinitions:
    firebase:
      authorizationUrl: ""
      flow: "implicit"
      type: "oauth2"
      x-google-issuer: "https://securetoken.google.com/<project_id>"
      x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
      x-google-audiences: "<project_id>"

【问题讨论】:

    标签: google-cloud-endpoints openapi google-cloud-endpoints-v2


    【解决方案1】:

    恐怕 Cloud Endpoints 无法识别您指定的通配符。

    引用文档:

    “Endpoints 仅支持对应于整个路径段的 URL 路径模板参数(由斜杠 / 分隔)。不支持对应于部分路径段的 URL 路径模板参数。”[1]

    通配符的解决方法是使用路径模板。 您可以使用花括号 {} 将 URL 的一部分标记为路径参数,使用您的示例:

    域/_ah/api/{value1}

    域/_ah/api/{value1}/{value2}

    域/_ah/api/{value1}/{value2}/{value3}

    请注意不要与路径模板重叠,如下例所示:

    /items/{itemid} ---> 这是有效的

    /items/{itemId}/subitem ----> 这是有效的

    /items/cat ----> 这是无效的

    [1]https://cloud.google.com/endpoints/docs/openapi/openapi-limitations#url_path_templating

    【讨论】:

      猜你喜欢
      • 2010-12-25
      • 2014-01-03
      • 2012-11-03
      • 2017-10-31
      • 2020-07-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      相关资源
      最近更新 更多