简体   繁体   English

具有多种身份验证令牌类型的Android AccountManager

[英]Android AccountManager with multiple auth token types

I've followed the syncadapter example to create an AccountManager and a sync adapter. 我已经按照syncadapter示例创建了AccountManager和同步适配器。 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. 一切正常,但我发现当我通过一种身份验证类型对(通过getauthtoken进行身份验证)时,保存它的过程将替换另一种身份验证类型。 I looked in the accounts.db file before and after. 我前后查看过accounts.db文件。 Before the call to get a token for authtoken type "B", the authtoken table in accounts.db has an authtoken for auth type "A". 在调用以获取身份验证类型“ B”的令牌之前,accounts.db中的身份验证表具有身份验证类型“ A”的身份验证令牌。 After the call, the authtoken table in accounts.db has an authtoken for type "B" but "A" was removed. 调用之后,accounts.db中的authtoken表具有类型为“ B”的authtoken,但“ A”已被删除。 No matter the order, the accountmanager subsystem never seems to store more than a single authtoken per account for my account type. 无论顺序如何,对于我的帐户类型,accountmanager子系统似乎永远不会为每个帐户存储一个以上的身份验证令牌。

Is there something special you need to configure in some xml file somewhere when you have more than one authtoken type? 当您具有多个身份验证类型时,是否需要在某处的某个xml文件中进行配置的特殊内容?

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. 如果成功进行身份验证/登录后调用AccountManager.setPassword(),它将使您帐户的所有身份验证令牌无效。 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. 随意将密码设置为相同值的软件将意外使它们的身份验证令牌无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM