2011-12-08 77 views
1

我正在嘗試創建Fitbit應用程序,爲此我更改了example Twitter Oauth app以從fitbit獲取數據。我現在運行到的問題是隨機,我會收到以下錯誤:Android Oauth隨機返回身份驗證錯誤「nonce_used」

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值,以及如何獲得新的值?

讓我知道如果在這裏發佈代碼是有益的。

回答

2

OAuth隨機數用於通過確保您所做的每個有效請求只能被接受一次來防止回放攻擊。

這是一段時間,因爲我搞砸OAuth,但我認爲你只需要包括一個隨機生成的字符串(我認爲我用系統時鐘時間串聯到請求的用戶名和MD5散列結果)作爲nonce爲您提出的每個請求。顯然,這需要被合併到您的簽名代碼中。

+0

感謝這有助於。 – Michaeldcooney