OAuth在标题中使用授权数据,但不在URL中
问题描述:
我试图在系统中使用Google的OAuth。我已经成功地整合了Twitter和LinkedIn,但我与Google有过难关。OAuth在标题中使用授权数据,但不在URL中
我已经有消费者密钥,消费者机密和有效的访问令牌。使用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中以param的形式发送(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的应用注册页面中声明的项目名称。我想我没有使用正确的消费者钥匙和消费者秘密。
对此的任何线索将不胜感激。 :)提前
大眼睛,我已经格式不正确的问题。我在URL参数中使用了oauth_token。我仍然得到 相同的错误。 –
你的例子现在有两个:access_token = myvalidtoken&oauth_token = oauthtoken –