Reputation: 29867
I would like to use oAuth to retrieve a user's ID and preferrably ONLY their ID and not their e-mail address, name or any other information.
In Android, I know how to use the Google Play APIs to obtain tokens and can bring up the dialog where the user grants permission to an app to have access to the requested data. I generally use the AccountManager to bring up the dialog that allows the user to select which email address to use for the account that will authorize the app. In this sense, I already have access to their email address, although I don't really need it. What I really want is the ID of the Google account associated with that email address. I also do not want to use Google+ as this requires accessing too much private information.
The scope I found closest was:
https://www.googleapis.com/auth/userinfo.email
However, since I already have access to their email address when they selected it from AccountManager, it doesn't seem to make sense asking the user for permission to their email address.
Is there a scope that I can call that retrieves just the user's account ID?
EDIT: Apparently I am not the only one pissed about this: http://www.club4850.com/?p=46970
This is why a company like WhatsApp became successful. They require no registration or access to any information about the user. Google's sign in displays the requested permission "Know who you are on Google" - Great way to lose a lot of users.
Upvotes: 1
Views: 1352
Reputation: 661
For anyone still looking:
There is this scope: https://www.googleapis.com/auth/userinfo.profile
The way I access it in NodeJs is like this (I know the question is for android but it's not going to be too different in Java I imagine):
const oauth2 = google.oauth2({
auth: oauth2Client,
version: 'v2'
});
const userInfo = await oauth2.userinfo.get();
const userId = userInfo.data.id
Upvotes: 0
Reputation: 29867
Doing more research, there is a solution. However, this does require allowing the user to divulge their email address. The solution is called Cross Client Identity:
https://developers.google.com/accounts/docs/CrossClientAuth Verifying Back-End Calls from Android Apps
Basically it works like this:
I've tested this out and it works. No need to store passwords on the device and no need to request any weird permissions that the user would get turned off with. However, the user has to live with divulging their email address but most will generally have less problem with that. You can however tell your user in the app that you don't store their email address or other info if that helps to gain more trust.
Here is also an online tool that can decode JWT tokens that you can use during development to quickly see what data the token contains:
Upvotes: 1