OAuth使用标头中的授权数据,但不在URL中

时间:2011-08-30 18:43:46

标签: oauth

我正在尝试在我的系统中使用Google的OAuth。我已经成功整合了Twitter和LinkedIn,但我在谷歌遇到了困难。

我已经拥有了消费者密钥,消费者密钥和有效的访问令牌。使用G的OAuth游乐场,我拨打受保护资源(https://mail.google.com/mail/feed/atom)。我已使用此范围生成令牌。

使用HTTP标头中的授权数据:

GET /mail/feed/atom HTTP/1.1
Host: mail.google.com
Accept: */*
Authorization: OAuth oauth_version="1.0", oauth_nonce="nounce", oauth_timestamp="1314727855", oauth_consumer_key="myconsumerkey", oauth_token="myvalidtoken", oauth_signature_method="HMAC-SHA1", oauth_signature="signature"
Content-Type: application/atom+xml
GData-Version: 2.0

我从中获得的响应是​​一个有效的HTTP调用:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=UTF-8
Set-Cookie: S=gmail=yp_A23KtGOD9:gmproxy=PxCjSERnJWBbe; Path=/mail; Secure
Date: Tue, 30 Aug 2011 18:10:55 GMT
Expires: Tue, 30 Aug 2011 18:10:55 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Content-Length: 353
Server: GSE
<XML response here>

但是,(并且出现错误),使用相同的访问令牌,但在URL中将其作为参数发送(https://mail.google.com/mail/feed/atom? oauth_token = myvalidtoken < /强>):

GET /mail/feed/atom?oauth_version=1.0&oauth_nonce=nonce&oauth_timestamp=1314729533&oauth_consumer_key=myconsumerkey&access_token=myvalidtoken&oauth_token=oauthtoken&oauth_signature_method=HMAC-SHA1&oauth_signature=signature HTTP/1.1
Host: mail.google.com
Accept: */*
Content-Type: application/atom+xml
GData-Version: 2.0

我收到401错误:

HTTP/1.1 401 Unauthorized
Content-Type: text/html; charset=UTF-8
WWW-Authenticate: BASIC realm="New mail feed"
Content-Length: 147
Date: Tue, 30 Aug 2011 18:38:53 GMT
Expires: Tue, 30 Aug 2011 18:38:53 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
<HTML about my 401>

修改

我看到了这个例子,我尝试使用匿名作为消费者密钥和消费者秘密。现在它可以工作......但我需要向用户显示在Google的应用注册页面中声明的项目名称。我想我没有使用正确的消费者密钥和消费者秘密。

任何关于此的线索将不胜感激。 :) 提前致谢

1 个答案:

答案 0 :(得分:3)

http://tools.ietf.org/html/rfc5849#section-3.5.3

在OAuth 1.0中,参数名称为oauth_token而不是access_token ...