Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine Java - Federated Login, what to keep in Datastore

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

like image 829
planetjones Avatar asked Nov 06 '22 03:11

planetjones


1 Answers

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.

like image 171
matt b Avatar answered Nov 12 '22 11:11

matt b