我意识到这并不是什么新鲜事,并且已经有很多关于这个主题的帖子。但是,与我正在寻找的内容不完全相关......所以,这里是:
我已经查看了有关此主题的所有其他帖子,但似乎没有什么对我有用。这是我正在做的事情的快速总结:
***我已经在这很长时间了,以至于我忘记了我在哪里 - 我刚刚意识到我的 oauth_signature 现在从我的授权标头中丢失了。我知道它以前在那里...
顺便说一句-我正在使用 Harry Klein 的 CF oauth 应用程序(http://oauth.riaforge.org/):
<!--- set up the parameters --->
<cfset sConsumerKey = 'xxx'> <!--- Got these from Tumblr for my app --->
<cfset sConsumerSecret = 'xxx'> <!--- Got these from Tumblr for my app --->
<cfset OAUTH_VERIFIER = 'xxx' /> <!--- Got these when doing oauth registration with tumblr for account --->
<cfset token = 'xxx' /> <!--- Got these when doing oauth registration with tumblr for account --->
<cfset tokenSecret = 'xxx' /> <!--- Got these when doing oauth registration with tumblr for account --->
<!--- set up the required objects including signature method--->
<cfset oReqSigMethodSHA = CreateObject("component", "oauth.oauthsignaturemethod_hmac_sha1")>
<cfset oToken = CreateObject("component", "oauth.oauthtoken").init(sKey = token, sSecret = tokenSecret)>
<cfset oConsumer = CreateObject("component", "oauth.oauthconsumer").init(sKey = sConsumerKey, sSecret = sConsumerSecret)>
<cfset oReq = CreateObject("component", "oauth.oauthrequest").fromConsumerAndToken(
oConsumer = oConsumer,
oToken = oToken,
sHttpMethod = "GET",
sHttpURL = 'http://api.tumblr.com/v2/user/info')> <!--- For now, just trying to get the user info --->
<!--- The ultimate goal is to post to differnent blog accounts on tumblr --->
<cfset oReq.setParameter('oauth_verifier',oauth_verifier) /> <!--- Had to manually add in oauth_verifier if it is even needed --->
<cfset oReq.signRequest(
oSignatureMethod = oReqSigMethodSHA,
oConsumer = oConsumer,
oToken = oToken)> <!--- Sign the request --->
<cfhttp url="#oReq.GETNORMALIZEDHTTPURL()#" method="get">
<cfhttpparam type="header" name="authorization" value="#oReq.TOHEADER()#" />
</cfhttp>
<cfdump var="#cfhttp#" />
这是我得到的一些内容(我添加了换行符以使其更清晰):
SIGNATUREBASESTRING:
GET&
http%3A%2F%2Fapi.tumblr.com%2Fv2%2Fuser%2Finfo&
oauth_consumer_key%3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%26
oauth_nonce%3D96A76129198ADF9B60874521D3FB718256B2D093%26
oauth_timestamp%3D1358463090%26
oauth_token%3Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%26
oauth_verifier%3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%26
oauth_version%3D1.0
AUTHORIZATION HEADER:
OAuth oauth_consumer_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
oauth_timestamp="1358463090",
oauth_version="1.0",
oauth_nonce="96A76129198ADF9B60874521D3FB718256B2D093",
oauth_token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
oauth_verifier="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
每次我尝试修改任何东西时,它都无法正常工作。我总是从 Tumblr 收到 401 Not Authorized 回复,但没有解释我做错了什么。
我已经在这几天了:请帮忙
* 2013 年 1 月 24 日编辑**
1. Getting the access_token:
response from Tumblr to auth_token request (Success):
oauth_token=XXX&
oauth_token_secret=XXX&
oauth_callback_confirmed=true
2. Using access token to get user info:
sConsumerKey:
xxx
sConsumerSecret:
yyy
EndPoint:
http://api.tumblr.com/v2/user/info
COMMETHOD:
get
token:
XXX
tokenSecret:
XXX
Signature base string:
GET&
http%3A%2F%2Fapi.tumblr.com%2Fv2%2Fuser%2Finfo&
oauth_consumer_key%3Dxxx&
oauth_nonce%3DDED2857752C210C71D81DFD549B7B13113DCA50F&
oauth_signature_method%3DHMAC-SHA1&
oauth_timestamp%3D1358993908&
oauth_token%XXX&
oauth_version%3D1.0
Signature:
emffJ8+2QvExJzRH0fgDM8l3jDQ=
Authorization Header:
OAuth oauth_consumer_key="xxx"&
oauth_nonce="DED2857752C210C71D81DFD549B7B13113DCA50F"&
oauth_signature="emffJ8%2B2QvExJzRH0fgDM8l3jDQ%3D"&
oauth_signature_method="HMAC-SHA1"&
oauth_timestamp="1358993908"&
oauth_token="XXX"&
oauth_version="1.0"
验证: 1. OAuth_token 正确。2. oAuth Header 按字母顺序排序。3. 签名基本字符串不包含参数,因为没有。4.方法是get。5. OAuth Header 包含 oauth_signature。
一些问题是: 1. 我是否需要包含任何其他标头(不确定 CF 是否自动添加任何标头) 2. 任何人都可以验证我的签名基本字符串吗?3. 签名基串是否有区分大小写的问题?(或其他任何地方)
编辑- 2013 年1 月 27 日 任何人都可以确认此信息(我使用的是真实值,因为在包括应用程序本身后一切都会被重置):
Given:
1. Signature Base String:
GET&
http%3A%2F%2Fapi.tumblr.com%2Fv2%2Fuser%2Finfo&
oauth_consumer_key%XXX%26
oauth_nonce%3DOAUTH7DC9F837D60483B9D10389C9BB0AEAF9%26
oauth_signature_method%3DHMAC-SHA1%26
oauth_timestamp%3D1359320053%26
oauth_token%XXX%26
oauth_version%3D1.0
2. Signing Key (consumer secret & auth_token_secret):
XXX&
XXX
Is this signature correct?
3. Signature:
2n+xbj9gbOrADeaQ3nORKNhOTUg=
Is this Authorization Header correct:
4. Authorization header (FYI- there is a space after each comma- is that ok?
And- is the encoding on the Signature ok?):
(Also, I've tried this in alphabetical order and not- same result)
OAuth oauth_signature="2n%2Bxbj9gbOrADeaQ3nORKNhOTUg%3D",
oauth_token="XXX",
oauth_consumer_key="XXX",
oauth_nonce="OAUTH7DC9F837D60483B9D10389C9BB0AEAF9",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1359320053",
oauth_version="1.0"
我希望有人可以确认这是否正确。在后一种情况下,我会稍微调整一下,并希望再次检查。提前谢谢大家。