【问题标题】:AccountManager and OAuth - how to add account?AccountManager 和 OAuth - 如何添加帐户?
【发布时间】:2011-07-28 09:31:43
【问题描述】:

我的应用程序连接到使用 OAuth 授权的服务器。 我应该如何在账户管理器中存储这些账户? 如果我已经登录并通过,它可能如下所示:

        Account account = new Account("user1", context.getString(R.string.ACCOUNT_TYPE));
        AccountManager am = AccountManager.get(context);
        if (am.addAccountExplicitly(account, "pass1", null)) {
            result = new Bundle();
            Log.i(TAG, "account: "+account.name+", "+account.type);
            result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
            result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
            activity.setAccountAuthenticatorResult(result);

但是在 OAuth 帐户的情况下应该传递什么而不是用户名并传递? 我应该在哪里存储 OAuth-secret? OAuth 令牌应该存储在 KEY_AUTHTOKEN 中吗?

【问题讨论】:

    标签: android oauth accountmanager


    【解决方案1】:

    不要使用setAuthToken 的密码,而是将 OAuth 令牌放在那里:

    重要的是要了解 AccountManager 不是加密服务或钥匙串。它以纯文本形式存储帐户凭据,就像您传递它们一样。在大多数设备上,这不是一个特别的问题,因为它将它们存储在一个只能由 root 访问的数据库中。但是在有根设备上,任何对设备具有 adb 访问权限的人都可以读取凭据。

    考虑到这一点,您不应将用户的实际密码传递给 AccountManager.addAccountExplicitly()。相反,您应该存储一个对攻击者来说用途有限的加密安全令牌。如果您的用户凭据正在保护有价值的东西,您应该仔细考虑做类似的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-30
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 2011-10-02
      • 2015-05-17
      • 1970-01-01
      • 2013-02-26
      相关资源
      最近更新 更多