Android Oauth随机返回身份验证错误“nonce_used”

时间:2011-12-08 18:45:42

标签: android oauth

我正在尝试创建一个Fitbit应用,为此我更改了example Twitter Oauth app以从fitbit获取数据。我现在遇到的问题是随机我会收到以下错误:

12-08 18:36:46.274: W/DefaultRequestDirector(439): Authentication error: Unable to respond to any of these challenges: {oauth=WWW-Authenticate: OAuth realm="http%3A%2F%2Fapp4int.fitbit.com", oauth_problem="nonce_used"}
12-08 18:36:46.284: W/System.err(439): org.apache.http.client.HttpResponseException: Unauthorized
12-08 18:36:46.294: W/System.err(439):  at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:71)
12-08 18:36:46.294: W/System.err(439):  at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
12-08 18:36:46.294: W/System.err(439):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
12-08 18:36:46.294: W/System.err(439):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
12-08 18:36:46.294: W/System.err(439):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
12-08 18:36:46.305: W/System.err(439):  at org.knoesis.healthcare.HealthcareAppActivity$GetCredentialsTask.doInBackground(HealthcareAppActivity.java:149)
12-08 18:36:46.305: W/System.err(439):  at org.knoesis.healthcare.HealthcareAppActivity$GetCredentialsTask.doInBackground(HealthcareAppActivity.java:1)
12-08 18:36:46.305: W/System.err(439):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
12-08 18:36:46.305: W/System.err(439):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-08 18:36:46.334: W/System.err(439):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-08 18:36:46.444: W/System.err(439):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
12-08 18:36:46.444: W/System.err(439):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
12-08 18:36:46.444: W/System.err(439):  at java.lang.Thread.run(Thread.java:1096)

其中有趣的部分是我研究过的'oauth_problem =“nonce_used”',它说“nonce_used:oauth_nonce值在之前的请求中使用,因此现在无法使用。”哪个值是oauth_nonce值,如何使用新值?

如果在这里发布有问题的代码是有益的,请告诉我。

1 个答案:

答案 0 :(得分:2)

OAuth nonce用于防止播放攻击,确保您发出的每个有效请求只能被接受一次。

自从我搞砸OAuth已经有一段时间了,但我认为你只需要包含一个随机生成的字符串(我想我将系统时钟时间连接到请求的用户名并将MD5哈希结果)作为nonce for你提出的每一个要求。显然,这需要合并到您的签名生成代码中。