简体   繁体   中英

Access UserService from Google Cloud Endpoint

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.

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 ). Getting the current user in Endpoints is done via injection in the method signature, eg:

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

I'm not sure how your local test is succeeding, but what I've described is the expected behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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