Question

I'm building a Google App Engine for Java app using Federated login.

When a user has logged into my app using an OAuth provider I get a User object back [http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/users/User.html].

I want to persist a link to that user in the datastore. However, what do I use as the unique key? Is it the getFederatedIdentity() or getUserId() ? There is hardly any JavaDoc on either. Obviously when a user subsequently logs into my app I want to retrieve the Object I have saved to the datastore.

I understand the federatedIdentity field, which I understand should always be populated (I only allow federated logons). However, if that's the field to use to link my details to the logged on user, then Google leaves this empty when testing on the local server... so that wouldn't be much use.

What is the getUserId field - how does Google set it? Will it guarantee to stay the same if the user's federated identity stays the same?

Thanks a lot

Was it helpful?

Solution

From the Users Java API Overview

While a user is signed in to an app, the app can access the account's email address or OpenID identifier for every request the user makes to the app. The app can also access a user ID that identifies the user uniquely, even if the user changes the email address for her account.

sounds like getUserId() is the best choice.

OTHER TIPS

You don't need to store either - you can store the User object directly in the datastore. See here for a list of supported object types.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top