Chrome扩展程序OATH 401错误(未经授权)

发布于 2024-11-07 08:46:04 字数 2828 浏览 0 评论 0原文

我正在使用 JS 访问 rdio 插件。我正在使用以下 Oauth http://code.google.com/chrome/extensions/ tut_oauth.html。 我能够获得签名令牌等。但是,当我尝试在 http://api 发送签名请求时.rdio.com/1/,我收到 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 我想我无法通过向 rdio API 发送 POST 请求。它给出了未经授权的错误。*

I am using JS to access the rdio plugin. I am using the following for Oauth http://code.google.com/chrome/extensions/tut_oauth.html.
I am able to get the signed token etc. However, when ever I try to send a signedRequest at http://api.rdio.com/1/, I receive 401, un-authorized error.

X-Mashery-Error-Code:ERR_401_INVALID_SIGNATURE
X-Mashery-Responder:mashery-web4.LAX

This is what I am trying to send:

 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);  

I receive the following error in console.

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    

*I am just trying to mimic what's mentioned here. Its an Oauth library(http://code.google.com/chrome/extensions/tut_oauth.html) from Google to make Chrome extension development easy.
They have an Oauth sample code to get your document list etc. http://code.google.com/chrome/extensions/samples.html#4e35caa9742fb82dbd628892d23a781614f6eff6
I think I am not able to get past send a POST requestto the rdio API. It gives an un-authorized error.*

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薔薇婲 2024-11-14 08:46:04

我们发现相同服务(rdio)和方法(“currentUser”)存在类似问题。

最终起作用的是:
(1) 确保 POST 正文中有 method=currentUser;从上面的卷曲输出中我不确定是否是这种情况。

而且,这实际上解决了问题:
(2) 我们还必须将方法名称添加到签名本身中。

仅供参考,我们使用了这个库:https://oauth.googlecode.com/svn/code/javascript/

但正如您所看到的,棘手的部分是弄清楚如何在创建签名的库中播种方法。如果没有“method=currentUser”作为签名的一部分,我们就会遇到相同的错误情况。

We found a similar issue with the same service (rdio) and method ("currentUser").

What ended up working was:
(1) make sure you have method=currentUser in the POST body; I'm not sure from the above curl output if that is the case.

And, this is the bit that actually fixed the issue:
(2) we had to also add the method name to the signature itself.

FYI we used this library: https://oauth.googlecode.com/svn/code/javascript/

But the tricky part, as you are seeing, was figuring out how to seed the method in that library that creates the signature. Without the 'method=currentUser' being part of the signature, we experienced the same error condition.

偏爱自由 2024-11-14 08:46:04

检查计算机上的时区、日期和时间。如果其中任何一项错误,OAuth 将失败。

Check your timezone, date, and time on your computer. If any one of these is wrong, OAuth will fail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文