簡體   English   中英

Chrome擴展OATH 401錯誤(未經授權)

[英]Chrome extension OATH 401 error(Unauthorized)

我正在使用JS訪問rdio插件。 我將以下內容用於Oauth http://code.google.com/chrome/extensions/tut_oauth.html 我可以獲取已簽名的令牌等。但是,每當我嘗試通過http://api.rdio.com/1/發送一個signedRequest時,都會收到401(未授權)錯誤。

X-Mashery-錯誤代碼:ERR_401_INVALID_SIGNATURE X-Mashery-Responder:mashery-web4.LAX

這是我要發送的:

 var url = 'http://api.rdio.com/1/';
 var request = {
   'method': 'POST',
   'headers': {
     'Content-Type': 'application/x-www-form-urlencoded'
   },    
   'parameters': {
     'alt': 'json',
     'method':'currentUser'
   },
   'body': 'Data to send'
 };

 bgPage.oauth.sendSignedRequest(url, mycallback, request);  

我在控制台中收到以下錯誤。

Request URL:http://api.rdio.com/1/?alt=json&method=currentUser&oauth_consumer_key=yv8ehzehdv55**********&oauth_nonce=******&oauth_signature=**********&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1305190893&oauth_token=us6myp99p4qc86umea9p8fp*****************
Request Method:POST
Status Code:401 Unauthorized
Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:12
Content-Type:application/x-www-form-urlencoded
Cookie:__qca=P0-158278476-1296771701175; r=eyJfdSI6IDE5MjY1LCAiX2UiOiAzMTU1NjkyNn0.SvN8xd7rIuLzTp7hxqi4eJEdvu8; __utmz=225830489.1305153361.198.18.utmcsr=rdioquiz.ianloic.com|utmccn=(referral)|utmcmd=referral|utmcct=/; __utma=225830489.281668250.1296676147.1305184513.1305187119.201; __utmc=225830489
Host:api.rdio.com
Origin:chrome-extension://oiojbkkpmcgmpnjkhjmaggajckamjkap
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_6) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.65 Safari/534.24
Query String Parameters
alt:json
method:currentUser
oauth_consumer_key:yv8ehzehdv55pbb74ss9dt23
oauth_nonce:BQF0x
oauth_signature:KttF************tRO 8PL yjPF2Ktk=
oauth_signature_method:HMAC-SHA1
oauth_timestamp:1305190893
oauth_token:us6myp99p4qc86umea9p8fphbgq4dxdd76txvyn***********
Form Data
Data to send:
Response Headers
Accept-Ranges:bytes
Content-Length:30
Content-Type:text/xml
Date:Thu, 12 May 2011 09:01:33 GMT
Server:Mashery Proxy
X-Mashery-Error-Code:ERR_401_INVALID_SIGNATURE
X-Mashery-Responder:mashery-web4.LAX    

*我只是想模仿這里提到的內容。 它是Google提供的Oauth庫(http://code.google.com/chrome/extensions/tut_oauth.html),可簡化Chrome擴展程序的開發。 他們有一個Oauth示例代碼來獲取您的文檔列表等。http ://code.google.com/chrome/extensions/samples.html#4e35caa9742fb82dbd628892d23a781614f6eff6我想我無法過去將POST請求發送到rdio API。 它給出了未經授權的錯誤。*

我們發現相同的服務(rdio)和方法(“ currentUser”)存在類似的問題。

最終的工作是:(1)確保POST正文中有method = currentUser; 我不確定從上面的curl輸出中是否是這種情況。

並且,這實際上是解決問題的方法:(2)我們還必須將方法名稱添加到簽名本身。

僅供參考,我們使用了以下庫: https : //oauth.googlecode.com/svn/code/javascript/

但是,正如您所看到的,棘手的部分是弄清楚如何將方法植入創建簽名的庫中。 沒有將“ method = currentUser”作為簽名的一部分,我們遇到了相同的錯誤情況。

在計算機上檢查您的時區,日期和時間。 如果其中任何一個錯誤,OAuth將失敗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM