Cloud Endpoints: Control who can execute API through API Explorer

限于喜欢 提交于 2019-11-28 14:24:46
sam
  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')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!