AuthToken from AccountManager in Android Client no longer works

I am very annoyed. I am trying to create a turn-based multiplayer online game for Android using the Google App Engine in Java as a server.

They seem perfect. Android requires a Google account, and GAE uses a Google account for authentication, being free and scalable.

So, before the holidays, I was able to get authentication in my GAE application from my Android client using the new AccountManager API in Android 2.0. The following code allows you to access the AuthToken Google user account and then use it for authentication so that the user does not have to manually enter the user name and password of the account:

AccountManager mgr = AccountManager.get(this); Account[] accts = mgr.getAccountsByType("com.google"); Account acct = accts[0]; AccountManagerFuture<Bundle> accountManagerFuture = mgr.getAuthToken(acct, "ah", null, this, null, null); Bundle authTokenBundle = accountManagerFuture.getResult(); String authToken = authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString(); 

Then I was able to add the resulting AuthToken string to the corresponding URL and get a valid cookie, which I could then use for all subsequent requests. The only thing is that last week it just stopped working for me. Now, when I try to use AuthToken from the above code, I don't get a cookie, and my code throws a NullPointerException for the missing cookie.

When I go back to the old way, when the user manually entered the Google username and password, and I get AuthToken from https://www.google.com/accounts/ClientLogin ", it works fine.

Please tell me, someone built an Android client for the Google App Engine application there using AuthToken from the Google account on the user's phone, and let me know why this does not work anymore.

I would really like to do this job. My alternatives require the user to enter their credentials (which is inconvenient, and what they don’t need to do), or is going with another server solution.

Thanks in advance.

+37
android authentication google-app-engine accountmanager
Jan 03 '09 at 23:01
source share
2 answers

Get help from a Google engineer. Turns out my authToken has expired. First, I started implementation in early December (more precisely, on the 9th). Apparently what the AccountManager does is the authToken cache, so I used the same authToken from December 9th. When I returned from vacation, it expired.

To solve this problem, I now call getAuthToken, then I call invalidateAuthToken on this token, and then I getAuthToken again. This generates a valid authToken and works fine even if it is a little clumsy and not needed if the AccountManager just received a new authToken every time or checked to see if the cache has expired.

Please note that you should not mix the type of token with the type of account: invalidateAuthToken must be called using "com.google" instead of "ah" or it will fail.

+26
Jan 07
source share

not an answer in itself, but I had to substitute β€œah” on β€œandroid” in line 4 to get the correct token on the android nexus with android v2.2.1. not sure about other devices / versions. line 4 then goes from:

 ... = mgr.getAuthToken(acct, "ah", null, this, null, null); 

at:

 ... = mgr.getAuthToken(acct, "android", null, this, null, null); 
+4
Oct 20 '10 at 15:01
source share



All Articles