我如何使用 AndroidAccountManager 注销

发布于 2024-10-19 13:33:53 字数 255 浏览 7 评论 0原文

我可以使用以下代码登录 Android AccountManagerhttp://code.google.com/p/google-api -java-client/wiki/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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别理我 2024-10-26 13:33:53

你不知道。当您使用内置的 Android 身份验证时,您可以使用用户在“帐户和同步”控制面板中提供的用户名和密码进行身份验证。一旦获得该身份验证,您就可以使用它来获取一个身份验证令牌,您应该缓存并使用该令牌,直到它变坏为止。

那么,让我们来看看使用“com.google”样式帐户访问谷歌服务的方式。当您的应用程序想要同步时,您最终将使用 AccountManager 进行身份验证(您绝对应该使用 SyncAdapter 来执行此操作)。一旦您进行身份验证,您将获得一个身份验证令牌。这是一串随机字母,充当后续网络调用的“密钥”。您将保存此信息,只要它是好的,您就不需要再次进行身份验证。所以,想要获取......比方说,谷歌金融投资组合。您将 auth-token 包含在 http get 标头中。发生以下两种情况之一:

  1. Google 喜欢该令牌并使用它(代替用户名/密码对)对您进行身份验证,并返回您的请求的数据。
  2. Google 返回 http 错误 40x,表明您提供的身份验证令牌不好。

发生后一种情况有两个原因:

  1. 太旧了。 Google 希望您定期重新进行身份验证(就像您必须每周或每两周在 gmail.com 上输入密码以确保仍然是您本人一样。)当发生这种情况时,使身份验证令牌无效(有一个函数调用)并获得一个新的。
  2. 自从您获得身份验证令牌后,用户已更改密码。同样的事情,除了一路上,设备将无法进行身份验证,然后会向用户抱怨他们需要重新输入密码,在他们这样做之前,您将获得 NULL 身份验证令牌,或者调用将阻塞,直到他们获得密码(取决于您使用哪个函数调用来获取令牌)。

无论如何,您永远不会退出。您只需使用已获取并缓存的身份验证令牌来使用该服务,直到您不再这样做为止。将您获得的身份验证令牌视为会话密钥,只要您使用它,它就保持有效。

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.

八巷 2024-10-26 13:33:53

为什么不通过调用

 AccountManager.getInstance().invalidateAuthToken(accountType, currentToken);

AccountManager.invalidateAuthToken 文档

Why not just invalidate your current auth token by calling

 AccountManager.getInstance().invalidateAuthToken(accountType, currentToken);

AccountManager.invalidateAuthToken Documentation

野侃 2024-10-26 13:33:53

AccountManager 清除密码(帐户帐户)

从 AccountManager:

忘记已保存的密码。这会删除密码的本地副本;
它不会更改服务器上的用户帐户密码。拥有
setPassword(account, null) 效果相同,但需要更少
权限,并且可以由应用程序或管理界面使用
从帐户“注销”。

AccountManager clearPassword (Account account)

From the AccountManager:

Forgets a saved password. This erases the local copy of the password;
it does not change the user's account password on the server. Has the
same effect as setPassword(account, null) but requires fewer
permissions, and may be used by applications or management interfaces
to "sign out" from an account.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文