2017-03-01 73 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') 
    
    相關問題