AccountManager.confirmCredentials 问题

AccountManager.confirmCredentials issue

我正在尝试使用 AccountManager.confirmCredentials 方法在我的应用程序中进行用户验证。我是这样使用它的:

    AccountManager am = AccountManager.get(ctx);
    am.confirmCredentials(account, null, ctx, new AccountManagerCallback<Bundle>() {
        @Override
        public void run(AccountManagerFuture<Bundle> amf) {
            try {
                Bundle b = amf.getResult();
                boolean r = b.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
                vc.onValidateResult(r);
                return;
            } catch (OperationCanceledException ignore) {
            } catch (AuthenticatorException ignore) {
            } catch (IOException ignore) {
            }
            vc.onValidateResult(false);
        }
    }, null);

但发现自Android以来的实施存在差距 5. 用户可以在Google授权表中清除建议的帐户名称并使用his/her自己的。 结果将是肯定的,并且无法验证请求的帐户名是否用于确认,因为获取的包只有时间戳和结果布尔值。换句话说,捆绑包没有 KEY_ACCOUNT_NAME 字段,但是,根据它应该的引用。

有人知道如何解决此漏洞吗?

根据文档:

If no activity or password was specified, the returned Bundle contains KEY_INTENT with the Intent needed to launch the password prompt. Also the returning Bundle may contain KEY_LAST_AUTHENTICATED_TIME indicating the last time the credential was validated/created.

如果您的结果不包含帐户名称,则一定是由于上述情况。 您应该检查意图是否包含 KEY_INTENT,如果包含则启动该意图进行验证。

它已被 Google 修复。现在无需更改代码即可按预期工作。