Search code examples
androidaccountmanagerauth-token

Android AccountManager with multiple auth token types


I've followed the syncadapter example to create an AccountManager and a sync adapter. I wanted to have two different types of authtokens for different purposes (access to different services - the sync adapter uses one of them) under the same account.

Things work but I have found that when I authenticate (via getauthtoken) for one authtoken type, the process of saving it replaces the other authtoken type. I looked in the accounts.db file before and after. Before the call to get a token for authtoken type "B", the authtoken table in accounts.db has an authtoken for auth type "A". After the call, the authtoken table in accounts.db has an authtoken for type "B" but "A" was removed. No matter the order, the accountmanager subsystem never seems to store more than a single authtoken per account for my account type.

Is there something special you need to configure in some xml file somewhere when you have more than one authtoken type?


Solution

  • I found my problem. If you call AccountManager.setPassword() as a result of a successful authentication/login, it will invalidate all of the authentication tokens for your account. This is an undocumented side effect and in some cases, it kind of makes sense. Software that sets the password to the same value indiscriminately will accidentally invalidate their auth tokens.