2017-03-01 71 views
1

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

我想限制执行通过API浏览器的API只是一些用户的能力。但同时我的Android和iOS应用程序的所有用户都可以访问该API。

保障至少Android应用程序是通过Android客户端ID和SHA指纹便利的情况。所以,这里的范围是不包括应用程序访问安全性。

回答

1
  1. 标识该请求通过API资源管理器来了。一种方法是通过标题中的origin/referrer。要获得标题信息,请参阅question

而且,

  • 如果用户的列表是已知的,在端点方法提高endpoints.UnauthorizedException如果用户(endpoints.get_current_user())不是在列表中。
  • 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') 
    
    相关问题