Permanent Unique User Identifier

9 views
Skip to first unread message

Ryan Lamansky

unread,
Nov 3, 2008, 5:46:57 PM11/3/08
to Google App Engine
Is there a good way to establish a permanent unique user identifier?

All we have now is the email address. If the user changes this, they
lose access to all content they're associated with.

Ideally, I'd like some kind of user ID so that I can incorporate it
into a key name, thus providing efficient, quick, and dependable
access...

-Ryan

Mahmoud

unread,
Nov 3, 2008, 7:27:25 PM11/3/08
to Google App Engine
Use entity.key(). You can easily create your own AppUser entity that
wraps the users API user entity. See: http://code.google.com/appengine/docs/users/userobjects.html

yejun

unread,
Nov 3, 2008, 8:37:16 PM11/3/08
to Google App Engine
Allow multiple email address per user.

On Nov 3, 5:46 pm, Ryan Lamansky <Spam...@kardax.com> wrote:

Ryan Lamansky

unread,
Nov 3, 2008, 10:35:51 PM11/3/08
to Google App Engine
Mahmoud: The problem is that won't recognize if the user changes their
email address; it'll create a new entity and the user will lose
everything.

yejun: I thought about that, but there's no way to automatically know
that a new email address was changed from some old one. User
interaction is required. This requires an additional security system
to be built to verify that the user did indeed have the old email
address originally. There's also a possibility that the user will
start creating new content before realizing there's a problem,
creating the hassle of trying to merge the accounts.

yejun

unread,
Nov 4, 2008, 12:29:54 AM11/4/08
to Google App Engine
Why not just let user choose a user name?

Mike Wesner

unread,
Nov 5, 2008, 5:49:40 PM11/5/08
to Google App Engine
If you save the user it has a key, and you can get a unique string
from it like this:

unique_keystring = str(myUser.key())

If you just want a unique string to use as a key, you could do this:

import uid
unique_key = str(uuid.uuid4())

Many ways to do it. I use keystrings because with a keystring you
can do db.get(keystring) or even pass a list of key strings and its
fast. If you use some property you have to query.

-Mike

Ryan Lamansky

unread,
Nov 6, 2008, 3:12:50 PM11/6/08
to Google App Engine
yejun: I want to use Google's authentication system, not make my own.

Mike Wesner: Your solution fails if the user changes their email
address. Read my whole post. If, following your design, the user
changes their email address, it'll look like a new user with a new key
and everything... causing them to become disconnected with everything
attached to their old address/key/whatever.

-Ryan

Wooble

unread,
Nov 6, 2008, 4:00:28 PM11/6/08
to Google App Engine
Yes. That's the negative side to using Google's authentication system.

Alexander Kojevnikov

unread,
Nov 6, 2008, 8:08:24 PM11/6/08
to Google App Engine
Ryan,

May be I'm missing something, but why not use a UserProfile model and
reference *it* instead of the User:

class UserProfile(db.Model):
user = db.UserProperty()
...

UserProfile would use a generated integer key id, or a custom key_name
(e.g. a prefixed uuid4 string).

You would then reference the user profile in your models:

class Comment(db.Model):
who = db.ReferenceProperty(reference_class=UserProfile)

If the user changes her e-mail, the references will not not affected.

app-engine-patch has built-in support for this, if you are using
Django you might want to take a look:
http://code.google.com/p/app-engine-patch/wiki/GoogleAccounts

Ryan Lamansky

unread,
Nov 7, 2008, 2:09:06 PM11/7/08
to Google App Engine
Alexander Kojevnikov: Although your plan would function, it offers no
protection from email address changes. If the user changes their
email address, they would no longer match their original UserProfile
(because UserProperty is just a fancy name for "string", as it stores
only the email address), thus cutting them off from all referenced
data.

-Ryan

Alexander Kojevnikov

unread,
Nov 7, 2008, 5:56:10 PM11/7/08
to Google App Engine
Ryan,

I see now. It looks like Google is going to fix this in the future,
see the last paragraph on this page:
http://code.google.com/appengine/docs/users/userobjects.html

I couldn't find an issue for this, adding one would speed this up...

Alex

yejun

unread,
Nov 7, 2008, 6:21:53 PM11/7/08
to Google App Engine
Google openid already supports persistent id independent of user name
or email address.

http://code.google.com/apis/accounts/docs/OpenID.html

On Nov 7, 5:56 pm, Alexander Kojevnikov <alexan...@kojevnikov.com>
wrote:
Reply all
Reply to author
Forward
0 new messages