我正在使用AppEngine Cloud Endpoints和Javascript客户端和Google+登录,我正在使用endpoints.get_current_user()
。有没有办法检查用户是否是AppEngine管理员?与用户API中的users.is_current_user_admin()
类似。有没有办法在AppEngine Cloud Endpoints中检查用户是否是管理员
由于
我正在使用AppEngine Cloud Endpoints和Javascript客户端和Google+登录,我正在使用endpoints.get_current_user()
。有没有办法检查用户是否是AppEngine管理员?与用户API中的users.is_current_user_admin()
类似。有没有办法在AppEngine Cloud Endpoints中检查用户是否是管理员
由于
为ID令牌并执行身份验证时承载的令牌之间的差的一个长的描述见Google Endpoints API + Chrome Extension returns None for endpoints.get_current_user().user_id()。
如果您不使用Android应用程序,则可以自由使用持票人令牌,而不必担心身份证令牌的某些限制。
接下来get_current_user()
,oauth
库提供oauth.is_current_user_admin()
方法。正如get_current_user()
,this method calls_maybe_call_get_oauth_user
然后检查一个简单的环境变量。
正如在其他答复中提到:
的
oauth.get_current_user()
电话是只买贵的IF它使 的RPC。_maybe_call_get_oauth_user
方法存储最后一次调用的值 ,所以第二次调用oauth.get_current_user()
时 将不会导致网络/速度开销超过几纳秒至 查找来自Pythondict
的值。
所以,如果你只使用承载令牌,你可以做以下
from google.appengine.api import oauth
from google.appengine.ext import endpoints
...
endpoints_user = endpoints.get_current_user()
if endpoints_user is None:
raise endpoints.UnauthorizedException(...)
is_admin = oauth.is_current_user_admin(known_scope)
if not is_admin:
# Throw a 403 FORBIDDEN
raise endpoints.ForbiddenException(...)