Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i log out with AndroidAccountManager

i can login with Android AccountManager with this code: http://code.google.com/p/google-api-java-client/wiki/AndroidAccountManager

But i don't know how to log out?

like image 824
Nam Vu Avatar asked Jan 21 '23 09:01

Nam Vu


1 Answers

You don't. When you use the built-in android authentication, you authenticate using the username and password that the user has provided in the "Accounts and Sync" control panel. Once you have that authentication, you use it to obtain an auth-token which you should cache and use until it goes bad.

So, let's go with the way you access google services using a "com.google" style account. You will end up authenticating using AccountManager, when your app wants to sync (You should definitely be using a SyncAdapter to do this). Once you authenticate, you will get an auth-token. this is a big string of random letters, which acts as a "key" on subsequent web calls. You will save this, and as long as it's good, you won't need to authenticate again. So, want go to fetch... let's say, a google finance portfolio. You include the auth-token as part of the http get header. One of two things happens:

  1. Google likes that token and uses it (in place of of a username/password pair) to authenticate you, and returns data for your request.
  2. Google returns http error 40x indicating that the auth-token youp provided is no good.

The latter case will happen for two reasons:

  1. It's too old. Google likes you to re-authenticate periodically (just like you have to enter your password at gmail.com every week or two to make sure it's still you.) When this happens, Invalidate the auth token (There's a function call) and get a new one.
  2. The user has changed their password since you got the auth token. Same thing, except along the way, the device will fail to authenticate, and then will complain to the user that they need to re-enter their password, and until they do, you'll either get a NULL auth token, or the call will block until they get a password (Depending on which function call you use to get the token).

In any case, you never log out. You just use the service with the auth token you've obtained and cached, until you don't anymore. Think of the auth token you get as being like a session key that stays good for as long as you're using it.

like image 179
jcwenger Avatar answered Jan 31 '23 01:01

jcwenger