检测通过 AccountPicker 选择的帐户是否在没有 GET_ACCOUNTS 权限的情况下仍然有效

Detecting if account selected via AccountPicker is still valid without GET_ACCOUNTS permission

在我的应用程序中,我使用 AccountPicker.newChooseAccountIntent() 让用户访问 select 一个帐户,然后使用 GoogleAuthUtil.getToken() 获取该帐户的授权令牌。

这一切都是在不需要 Marshmallow 的 GET_ACCOUNTS 许可的情况下完成的。

移动到 API 23 后我遇到的问题是我无法检测到 selected 帐户何时不再有效,因为 AccountManager.getAccountsByType() returns 是一个空列表对于 google 个帐户,因为我没有 GET_ACCOUNTS 权限。

使用 google 帐户 select 并在没有 GET_ACCOUNTS 的情况下进行身份验证的能力非常烦人,但缺乏检测帐户何时不再有效的能力。

有谁知道如何检测帐户何时不再有效?

您根本不应该使用 GoogleAuthUtil.getToken(),也不应该使用 AccountPicker.newChooseAccountIntent()。根据 Improving the Security and User Experience of your Google Sign In Implementation blog postgetToken() 容易受到令牌替换攻击。

您应该遵循 migration guide to use Google Sign In and the requestIdToken() flow。这使您可以 1) 知道登录的是哪个帐户 2) 知道该帐户何时不再有效以及 3) 仍然可以获得使用 Google 服务进行身份验证所需的令牌。