AccountManager 和 OAuth - 如何添加帐户?

发布于 2024-10-30 02:00:16 字数 723 浏览 4 评论 0原文

我的应用程序与服务器连接,该服务器使用 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 中吗?

My application connects with the server, which uses OAuth authorization.
How should I store such accounts in Account Manager?
In case I have login and pass, it can look like below:

        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);

But what should be passed instead of user name and pass in case of OAuth-account?
And where should I store OAuth-secret? OAuth token should be stored in KEY_AUTHTOKEN?

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

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

发布评论

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

评论(1

情何以堪。 2024-11-06 02:00:16

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

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

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

Don't use the password you could setAuthToken, put the OAuth token there instead:

It's important to understand that AccountManager is not an encryption service or a keychain. It stores account credentials just as you pass them, in plain text. On most devices, this isn't a particular concern, because it stores them in a database that is only accessible to root. But on a rooted device, the credentials would be readable by anyone with adb access to the device.

With this in mind, you shouldn't pass the user's actual password to AccountManager.addAccountExplicitly(). Instead, you should store a cryptographically secure token that would be of limited use to an attacker. If your user credentials are protecting something valuable, you should carefully consider doing something similar.

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