从Google Cloud Endpoint访问UserService

时间:2022-08-22 10:59:02

I am developing a Google App Engine app with a Cloud Endpoint. My app uses OpenID to authenticate a user. 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.

我正在使用Cloud Endpoint开发Google App Engine应用程序。我的应用使用OpenID来验证用户身份。一旦用户登录,在同一会话中,就会调用端点。在端点代码中,我想访问当前登录用户的用户服务。这适用于开发服务器,但在部署到Google之后,userService将null返回到getCurrentUser()调用。

Can I get the current logged in user during a cloud endpoint execution?

我可以在云端点执行期间获取当前登录用户吗?

1 个解决方案

#1


3  

You can't use the UserService within an Endpoint method (at least not one called via /_ah/api). Getting the current user in Endpoints is done via injection in the method signature, e.g.:

您不能在Endpoint方法中使用UserService(至少不能通过/ _ah / api调用)。在端点中获取当前用户是通过方法签名中的注入完成的,例如:

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.

我不确定你的本地测试是如何成功的,但我所描述的是预期的行为。

#1


3  

You can't use the UserService within an Endpoint method (at least not one called via /_ah/api). Getting the current user in Endpoints is done via injection in the method signature, e.g.:

您不能在Endpoint方法中使用UserService(至少不能通过/ _ah / api调用)。在端点中获取当前用户是通过方法签名中的注入完成的,例如:

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.

我不确定你的本地测试是如何成功的,但我所描述的是预期的行为。