Michael Stewart
Michael Stewart

Reputation: 13

How to avoid collisions with GAE Google user IDs?

Google App Engine provides user IDs from the Users service which are only promised to be:

an opaque string that uniquely identifies the user represented by this User object.

as per: https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/users/User#getUserId()

These strings always seem to be numeric with a length of 21 characters. Is there any guarantee from Google that they will always be numeric or any other promise more specific than just a String?

I ask because we'd like to store them alongside user IDs from other login providers such as Facebook and want to be sure that there will not be a collision if only the Facebook IDs have a prefix and the Google User IDs remain as is.

Upvotes: 1

Views: 67

Answers (2)

Andrei Volgin
Andrei Volgin

Reputation: 41089

If you consistently add "g_" prefix to Google ids and "f_" prefix to Facebook ids, all ids will always be unique, even if you encounter a Google id that starts with "f_".

Note, however, that we decided against the approach that you are taking, because (a) users may change their accounts linked to our app (and we don't want to change their datastore id and update all references in such cases, even though it's a rare usecase), and (b) we allow users to connect more than one external account to an account in our app.

Upvotes: 1

Amber
Amber

Reputation: 526593

If you want to guarantee no collisions between IDs from multiple different providers/APIs, you should add prefixes to both types to ensure that. When an API says it's an opaque string, it is explicitly not making guarantees about what the content of the string may be. Just because it is consistently a number now doesn't mean it will continue to be a number in the future.

Upvotes: 0

Related Questions