Cloud Endpoints: Control who can execute API through API Explorer

独自空忆成欢 提交于 2019-11-27 08:38:33

问题


Everyone who successfully authenticates through Google account would be able to execute the API through the API Explorer.

I would like to limit the ability to execute the API through API Explorer only to some users. But at the same time have the API accessible for all users of my Android and iOS apps.

Security in the case of at least Android App is facilitated through the Android Client Id and SHA fingerprint. So, the scope here is to NOT include the App access security.


回答1:


  1. Identify that the request is coming through the API explorer. One way is through the origin/referrer in the headers. For obtaining header information see this question.

And,

  1. If the list of users is known, in the endpoints method raise endpoints.UnauthorizedException if the user (endpoints.get_current_user()) is not in the list.

Python sample code:

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')


来源:https://stackoverflow.com/questions/42521424/cloud-endpoints-control-who-can-execute-api-through-api-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!