AccountManager 和 OAuth - 如何添加帐户?
我的应用程序与服务器连接,该服务器使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用您可以
setAuthToken
的密码,而是将 OAuth 令牌放在那里:Don't use the password you could
setAuthToken
, put the OAuth token there instead: