【问题标题】:Cloud Endpoints: Control who can execute API through API ExplorerCloud Endpoints:控制谁可以通过 API Explorer 执行 API
【发布时间】:2017-03-01 01:02:24
【问题描述】:

通过 Google 帐户成功进行身份验证的每个人都可以通过 API Explorer 执行 API。

我想将通过 API Explorer 执行 API 的能力限制为仅限于某些用户。但与此同时,我的 Android 和 iOS 应用程序的所有用户都可以访问 API。

至少 Android 应用程序的安全性通过 Android 客户端 ID 和 SHA 指纹来促进。因此,这里的范围是不包括应用程序访问安全性。

【问题讨论】:

    标签: google-cloud-endpoints


    【解决方案1】:
    1. 确定请求是通过 API 浏览器发出的。一种方法是通过标头中的来源/引荐来源网址。要获取标头信息,请参阅此question

    还有,

    1. 如果用户列表已知,如果用户 (endpoints.get_current_user()) 不在列表中,则在端点方法中引发 endpoints.UnauthorizedException

    Python 示例代码:

    if self.request_state.headers.get('x-referer') == "https://apis-explorer.appspot.com" and endpoints.get_current_user() not in MY_LIST:
      raise endpoints.UnauthorizedException('Not Authorized')
    

    【讨论】:

      猜你喜欢
      • 2016-03-21
      • 2018-03-19
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-28
      • 2015-07-13
      相关资源
      最近更新 更多