我今天一直与Oauth一起玩,并在API上实现了它。到目前为止,我正在使用iPhone应用程序消费API的服务,但我仍然想这样做,但是由于我添加了Oauth,因此使用它越来越困难,并且面临一些问题。

这是我所拥有的:

  • 提供者方
    • 一个小页,为消费者提供钥匙和秘密钥匙
    • request_token页面,向消费者提供令牌
    • 授权页面赋予用户授权使用令牌的权力
    • 最后是一个token_access页面,以更改访问令牌中的请求令牌以访问我的API
  • 在消费者方面,有:
    • 消费者密钥(由提供商端的页面生成)
    • 消费者秘密键(由提供商侧的页面生成)

这是我可以做的毫无问题的事情:

  • 获取请求令牌
  • 使用户授权令牌

当我试图将此令牌更改为访问令牌时,我会有一个错误:

OAuthException2: Signature verification failed (HMAC-SHA1)

看来我在某个地方缺少一些东西,但找不到什么!这是我在日志中发现的其他东西,可以有所帮助:

从消费者那里收到:

Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-us
Authorization: OAuth realm="", oauth_consumer_key="55af183bbbc2c386de3d0cb82a8bc4aa04d2883f9", oauth_token="4ba900b2cb3a6a67c13d0b089874649504d28c069", oauth_signature_method="HMAC-SHA1", oauth_signature="UKJXUjT4ZpEDeWFDVl7%2BUiqOids%3D", oauth_timestamp="1294516337", oauth_nonce="72D5BE27-D4DF-4C93-942F-96DCBCAB3509", oauth_version="1.0"
Connection: keep-alive
Cookie: PHPSESSID=676e088f8f13d7a1bb61d2437ee0b2a6
Host: localhost:8888
User-Agent: DearStranger/1.0 CFNetwork/485.12.7 Darwin/10.6.0

提供者的回答:

X-Powered-By: PHP/5.3.2
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: text/plain

OAuth Verification Failed: Verification of signature failed (signature base string was "GET&http%3A%2F%2Flocalhost%3A8888%2FDearStranger%2Fwebservices%2Foauth%2Faccess_token.php&oauth_consumer_key%3D55af183bbbc2c386de3d0cb82a8bc4aa04d2883f9%26oauth_nonce%3D72D5BE27-D4DF-4C93-942F-96DCBCAB3509%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1294516337%26oauth_token%3D4ba900b2cb3a6a67c13d0b089874649504d28c069%26oauth_verifier%3D1234%26oauth_version%3D1.0"). with  Array
(
    [0] => dd918316d0190cf48d6bd6028ecbd9fc
    [1] => ec0390f4ce6bbbe6a5f13a651f8b95ff
    [2] => request
)

我在iPhone方面使用OAuthConsumer(http://code.google.com/p/oauthconsumer)。这个框架做错了什么可以让我遇到这些错误?

感谢您的回答!

马丁

有帮助吗?

解决方案

我终于发现我没有以正确的方式为iPhone使用OAuthConsumer框架。我试图以与Twitter API使用相同的方式使用它,但是我的服务器曝光与Twitter的规格没有相同的规格。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top