简体   繁体   English

从Google Cloud Endpoint访问UserService

[英]Access UserService from Google Cloud Endpoint

I am developing a Google App Engine app with a Cloud Endpoint. 我正在开发带有Cloud Endpoint的Google App Engine应用。 My app uses OpenID to authenticate a user. 我的应用程序使用OpenID验证用户身份。 Once the user has logged in, in the same session, there is a call to the endpoint. 一旦用户登录,在同一会话中,便会呼叫端点。 In the endpoint code I want to access the user service for the current logged in user. 在端点代码中,我想访问当前登录用户的用户服务。 This works on the development server, but after deploy to Google the userService returns null to the getCurrentUser() call. 这可以在开发服务器上使用,但是在部署到Google后,userService将null返回给getCurrentUser()调用。

Can I get the current logged in user during a cloud endpoint execution? 在云端点执行期间是否可以获取当前登录的用户?

You can't use the UserService within an Endpoint method (at least not one called via /_ah/api ). 您不能在Endpoint方法中使用UserService(至少不能通过/_ah/api调用)。 Getting the current user in Endpoints is done via injection in the method signature, eg: 通过在方法签名中注入来使当前用户进入Endpoints,例如:

public Score insert(Score score, User user)

The User object will be populated with either: a valid user object (if the token sent into the request is valid) or null (if not). User对象将填充:有效的用户对象(如果发送到请求中的令牌有效)或null (如果无效)。

I'm not sure how your local test is succeeding, but what I've described is the expected behavior. 我不确定您的本地测试如何成功,但是我所描述的是预期的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM