Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function User.getUserId() in Cloud endpoint api returns null for a user object that is not null

I have a problem with getting the userid for a cloud endpoint method. I have used oauth2 authentication in my android client and passed the credentials to my service. The below is similar to what my method looks like (simplified to make it more clear).

I note that issue 8848 for python seems to be very similar to this problem.

Is the same issue a problem in java api as well? The method

public SuccessCode doSomething(WireFormat wire, User user){
    log.info("User id: "+user.getUserId());
    log.info("Federated identity: "+user.getFederatedIdentity());
    log.info("Email address: "+user.getEmail());
}

will show null for federated identity and userId even though credentials in android client have had oauth2 authentication performed. The email address shows up correctly in the log. This is all on a deployed application btw.

Anybody have any other suggestions as to what is wrong? Any known workarounds for the issue? I have followed the method suggested in https://developers.google.com/appengine/docs/java/endpoints/consume_android#making-authenticated-calls to set up my android client.

like image 886
user2072160 Avatar asked Apr 23 '13 13:04

user2072160


1 Answers

You're correct that issue 8848 is the same cause. The underlying issue is language-agnostic and affects both runtimes. At the moment you shouldn't expect the user ID field populated in a User object passed in via method argument in Endpoints.

A super suboptimal workaround is to persist the User object to the datastore and read it back. The re-read object will have the user ID included.

like image 182
Dan Holevoet Avatar answered Oct 21 '22 21:10

Dan Holevoet