I am using Google AppEngine and I am using the UserService class to process user accounts and login. you need to access any information about their account - I just use it to distinguish between users.
Now the website is basically a backend. I am using an android application for the interface. I know that you can access Google user accounts on the device using the AccountManager . This is definitely the safest way to get the user to log in. And I got so much work.
Where I am stuck, the login information from the Android application is transmitted to the AppEngine website. From what I'm ready, I have to use OAuth, and I see a walkthrough here to use it with the Google APIs, but I don't need to access the API, just to log in. I was able to get the authentication token in the application, but I'm not sure how to transfer it to the website, or even if this is the right direction. Should I use a specific OAuth login on the server, for example this guy ?
Any help would be greatly appreciated!
Here is the relevant code:
Server (GAE):
UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (user == null) { resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); return; }
Client (Android):
AccountManager am = AccountManager.get(this); Account[] accounts = am.getAccountsByType("com.google"); Bundle options = new Bundle(); am.getAuthToken( accounts[0], // Account retrieved using getAccountsByType() "Manage your tasks", // Auth scope options, // Authenticator-specific options this, // Your activity new OnTokenAcquired(), // Callback called when a token is successfully acquired new Handler(new OnError())); //Now what!?
source share