【问题标题】:How to set up custom user authentication with Google Cloud Endpoints如何使用 Google Cloud Endpoints 设置自定义用户身份验证
【发布时间】:2018-09-26 22:28:45
【问题描述】:

我正在尝试了解如何将 Cloud Endpoints 与自定义身份验证结合使用。从文档中我了解到它从securityDefinitions开始:

securityDefinitions:
    your_custom_auth_id:
      authorizationUrl: ""
      flow: "implicit"
      type: "oauth2"
      # The value below should be unique
      x-google-issuer: "issuer of the token"
      x-google-jwks_uri: "url to the public key"
      # Optional. Replace YOUR-CLIENT-ID with your client ID
      x-google-audiences: "YOUR-CLIENT-ID"

这是我对流程的理解:

  1. API 使用者发送带有 JWT 令牌的请求
  2. ESP 使用authorizationUrl 验证此令牌
  3. 请求被转发或 ESP 返回错误。

我的问题:

  • 上面的流程是否正确?
  • 应该如何实现authorizationUrl。请求看起来如何,成功或失败应该返回什么响应

  • 这个值呢? x-google-issuer:“令牌的发行者” x-google-jwks_uri:“公钥的 URL” x-google-audiences: "YOUR-CLIENT-ID"

【问题讨论】:

    标签: google-cloud-endpoints


    【解决方案1】:

    为端点配置自定义身份验证

    要为端点配置自定义身份验证(并根据 OpenAPI v2 规范),您需要两个部分:

    1. 在规范的securityDefinitions 部分定义您的自定义身份验证方案
    2. 使用security 字段将您的自定义身份验证方案(在#1 中定义)应用于entire apispecific operations

    Google Cloud Endpoints 文档描述了这个here

    OpenAPI 规范的安全定义

    OpenAPI 规范的 SecurityDefinitions 部分中的一些字段用于 API 生产者,而一些字段用于 API 使用者。

    以下字段用于API 生产者,并告诉端点如何验证伴随 API 请求的访问令牌:

    • 类型:“oauth2”
    • x-google-issuer:“令牌发行者”
    • x-google-jwks_uri: "公钥的 URL"
    • x-google-audiences: "YOUR-CLIENT-ID"

    这些字段由 API 生产者指定,并告诉消费者如何获取有效的访问令牌:

    • 授权网址

    回复:你的问题

    1. 正确。这里是documentation on how the consumer should send the access token with the request
    2. ESP 使用规范的x-google-jwks_uri 属性中指定的公钥验证访问令牌,并确保令牌的颁发者与securityDefinition 的x-google-issuer 字段中指定的颁发者匹配。
    3. 正确。

    关于您的问题,authorizationUrl 应由您使用的 OAuth2 提供程序设置。该 url 应该允许消费者执行隐式 OAuth2 流以获取访问令牌。你需要做的就是指定这个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-03
      • 2014-10-11
      • 2014-08-23
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 2013-06-02
      • 2018-12-29
      相关资源
      最近更新 更多