- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在帐户管理器和 OAuth-2 方面苦苦挣扎了一段时间,我已经实现了帐户管理器(带有服务和帐户验证器)、使用 webview 的登录 Activity 等。我实现了所有 oauth-2 流程,当用户在 webview 上输入其凭据时,我将访问 token 保存为 AccountManager 密码。当我向服务器发出 http 请求时,我现在知道的最后一件事是如何正确实现流程,它的响应是 Json with
{"message":"access_token_is_expired","error":true....}
所以我应该阅读此响应,分析它并使用 resresh token 执行另一个请求以获取另一个访问 token 。如何正确地实现这一点?在哪里?在什么类?可能是我的 Authenticator.getAuthToken 方法应该改进吗?这是代码:
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account,
String authTokenType, Bundle loginOptions) throws NetworkErrorException {
Log.v(TAG, "getAuthToken()");
if (!authTokenType.equals(Const.AUTHTOKEN_TYPE)) {
final Bundle result = new Bundle();
result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType");
return result;
}
final AccountManager am = AccountManager.get(mContext);
final String auth_token = am.getPassword(account);
if (auth_token != null) {
final Bundle result = new Bundle();
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, Const.ACCOUNT_TYPE);
result.putString(AccountManager.KEY_AUTHTOKEN, auth_token);
return result;
}
final Intent intent = new Intent(mContext, LoginActivity.class);
intent.putExtra(Const.KEY_SERVER, am.getUserData(account, Const.KEY_SERVER));
//intent.putExtra(LoginActivity.PARAM_AUTHTOKEN_TYPE, authTokenType);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
final Bundle bundle = new Bundle();
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
return bundle;
}
@Override
protected JSONObject doInBackground(Void... params) {
InputStream is = null;
try {
String url = "...";
URL obj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
String urlParameters = "access_token=" + mToken;
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
conn.connect();
int response_code = conn.getResponseCode();
is = conn.getInputStream();
String str_response = NetworkUtilities.readStreamToString(is, 500);
JSONObject response = new JSONObject(str_response);
return response;
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
我做了很多工作来理解这一点,但我失败了。
最佳答案
几天后,由于网上资料的运气,我在github上阅读了代码并做了一些研究。为了帮助像我这样的人:
可以在上面的getAuthToken 方法中重新请求过期的 token ,但是在 Bundle (loginOptions) 中添加应该从服务器重新请求的信息(例如,作为“forceReauth “=真)我在方法内部检查此参数并询问方法(上面的第二段代码),否则我使用通常的流程。
第二个重要的事情 - 我在这里看到的一行代码 Why is AccountAuthenticator#getAuthToken() not called?上帝保佑 Tom G(我不能给他投票,因为我名誉扫地)。代码行在 getAuthToken 之前使用 invalidateAuthToken 为我做了一切。如果您觉得这有用,请给他投一票。
关于android - 正确实现 AccountManager、oauth-2 和过期 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27491614/
我有一个 webapp,它使用 php 服务器和数据库服务器执行大量 ajax 请求。我还创建了一个 iPhone 应用程序和一个 Android 应用程序,直到现在它们一直作为离线应用程序工作。 现
OAuth 的访问 token /刷新 token 流对我来说似乎非常不安全。帮助我更好地理解它。 假设我正在与利用 OAuth 的 API 集成(如 this one )。我有我的访问 token
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: How is oauth 2 different from oauth 1 我知道这两个不向后兼容。但是,既然已经实
我已经看到关于此的其他问题( here 、 here 和 here ),但我对任何解决方案都不满意,所以我再次询问。我正在启动一个 Web 应用程序,它将利用来自多个提供商(Google、Facebo
我知道(在 OAuth 中使用授权代码“授权代码”时),访问 token 的生命周期应该很短,但刷新 token 的生命周期可能很长。 所以我决定为我的项目: 访问 token 生命周期:1 天 刷新
在没有浏览器的情况下,我们可以在手机上的应用程序中使用 OAuth 吗? 如果没有浏览器,用户是否仍然可以批准 token 请求(以便消费者可以继续从服务提供者那里获取 protected 资源)?
用非常简单的术语来说,有人可以解释一下 OAuth 2 和 OAuth 1 之间的区别吗? OAuth 1 现在已经过时了吗?我们应该实现 OAuth 2 吗?我没有看到很多 OAuth 2 的实现;
修改表单例份验证登录过程并不难,因此除了正常的表单例份验证之外,WebClient 对象对由使用 Thinktecture IdentityModel 设置的 Web Api DAL 提供的 api/
我想连接到 LinkedIn 并通过他们的 API 提取一些信息。 LinkedIn API 使用 OAuth 2.0。 我读过的所有关于 OAuth 的文档(无论是在 LinkedIn 的上下文中还
OAuth 与其他身份验证标准的支持范围有多广? 这可能是社区维基的东西,但我还是要问。 我需要投资一些与服务器身份验证相关的东西,而且那里似乎有一些不错的东西。 最佳答案 OAuth 主要用作授权机
我有几个问题... 雅虎和微软 api 是否支持 oAuth 2.0? 如果是,那么主要是什么 应该采取的安全措施 转移时受到照顾 oAuth 1.0 到 oAuth 2.0。 Google API
我已经用谷歌 oAuth 开发了一个应用程序,这工作正常。 我可以登录并访问我的网站。 我的问题是,当我从我的应用程序中注销(注销)时,我删除了所有 session ,但未删除经过身份验证的 cook
我在 Internet 上寻找一些关于此的信息,最后在 RFC 上找到了 Oauth 1.0 协议(protocol):https://www.rfc-editor.org/rfc/rfc5849 您
我正在尝试制作 Google OpenID/OAuth hybrid签到工作。问题是它是一个可安装的网络(所以没有固定域),我也试图让它在我的开发机器上工作 - 所以返回 URL 类似于 http:/
我想构建一个独立与任何身份提供者(如 ADFS、OpenAM、oracle 身份)一起工作的应用程序。我的目的是验证来自任何一个 IDP 的登录用户,这些 IDP 配置为实现我的 SSO。 我不确定
我正在深入研究 Spring OAuth,发现一些相互矛盾的信息。 具体来说,this tutorial声明 /oauth/token 端点在将刷新 token 授予客户端应用程序之前处理用户名和密码
如何通过自定义命令行工具支持三足式 OAuth 工作流? 我想允许我的 CLI 工具的用户上网、登录并在本地缓存 token ,类似于 heroku login。正在做。 最佳答案 你必须扔掉同意屏幕
什么是 oauth 域?是否有任何免费的 oauth 服务?我可以将它用于 StackApps registration 吗? ?我在谷歌上搜索了很多,但找不到答案。 最佳答案 这是redirect_
我需要将我的 Delicious 书签下载到非 Web 应用程序,而无需持续的用户交互。我正在使用 Delicious 的 V2 API(使用 oAuth),但问题是他们的访问 token 似乎在一小
我正在尝试为两台服务器设置一个 nginx 负载均衡器/代理,并在两台服务器上运行 OAuth 身份验证的应用程序。 当 nginx 在端口 80 上运行时,一切都运行良好,但是当我将它放在任何其他端
我是一名优秀的程序员,十分优秀!