无效的OAuth请求

时间:2011-02-23 00:20:52

标签: ruby-on-rails ruby oauth oauth-provider

您好,对不起我的英语。 我正在使用oauth 0.4.4和oauth-plugin 0.4.0.pre4 gems。 当我尝试以OAuth提供商的身份访问我的应用时

     8 consumer = OAuth::Consumer.new consumer_key, consumer_secret,
      9           :site => 'http://localhost:3000/', :scheme => :body
     10 
     11 request_token = consumer.get_request_token
消费者引发异常
    /home/lain/.rvm/gems/ruby-1.9.2-p136/gems/oauth-0.4.4/lib/oauth/consumer.rb:217:in token_request': 401 Unauthorized  (OAuth::Unauthorized)
        from /home/lain/.rvm/gems/ruby-1.9.2-p136/gems/oauth-0.4.4/lib/oauth/consumer.rb:139:inget_request_token'
        from private/test_app.rb:11:in `'

此请求的Rails日志是

Started POST "/oauth/request_token" for 127.0.0.1 at 2011-02-22 21:17:54 +0300
  Processing by OauthController#request_token as */*
  Parameters: {"oauth_body_hash"=>"2jmj7l5rSw0yVb/vlWAYkK/YBwk=", "oauth_callback"=>"oob", "oauth_consumer_key"=>"GAdP34UY4zunPwhm9hePODITteHxplQ3oShNPuKs", "oauth_signature_method"=>"HMAC-SHA1", "oauth_timestamp"=>"1298398673", "oauth_nonce"=>"aDRQijPyYJYODaqdZvpD2RMrReixMVcWb0zYSpjI", "oauth_version"=>"1.0", "oauth_signature"=>"0kYXwbPnNZK7JLpVVtnLs+H5klQ="}
Rendered text template (0.0ms)
Completed 401 Unauthorized in 10ms (Views: 2.7ms | ActiveRecord: 0.0ms)

当我尝试使用curl模拟此请求时,我将会得到

$ curl 'http://127.0.0.1:3000/oauth/request_token' -d 'oauth_body_hash=2jmj7l5rSw0yVb%2fvlWAYkK%2fYBwk%3d&oauth_callback=oob&oauth_consumer_key=GAdP34UY4zunPwhm9hePODITteHxplQ3oShNPuKs&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1298398673&oauth_nonce=aDRQijPyYJYODaqdZvpD2RMrReixMVcWb0zYSpjI&oauth_version=1.0&oauth_signature=0kYXwbPnNZK7JLpVVtnLs%2bH5klQ%3d' -v
* About to connect() to 127.0.0.1 port 3000 (#0)
*   Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 3000 (#0)
> POST /oauth/request_token HTTP/1.1
> User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: 127.0.0.1:3000
> Accept: */*
> Content-Length: 309
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 401 Unauthorized 
< Access-Control-Allow-Origin: *
< Content-Type: text/html; charset=utf-8
< Cache-Control: no-cache
< X-Ua-Compatible: IE=Edge
< X-Runtime: 1.245471
< Server: WEBrick/1.3.1 (Ruby/1.9.2/2010-12-25)
< Date: Tue, 22 Feb 2011 23:57:49 GMT
< Content-Length: 21
< Connection: Keep-Alive
< 
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0
Invalid OAuth Request

我的数据库包含一个ClientApplication

   ruby-1.9.2-p136 :001 > ClientApplication.all.to_a
     => [#<ClientApplication _id: 4d62f535e4279b2dec000001, created_at: 2011-02-21 23:28:53 UTC, updated_at: 2011-02-21 23:28:53 UTC, name: "...", url: "...", support_url: nil, callback_url: nil, key: "GAdP34UY4zunPwhm9hePODITteHxplQ3oShNPuKs", secret: "EQAD5fifIuC3qtAyrkIpqAEn39rK50Az55gxbVYD", user_id: nil>] 

我曾尝试过很多版本的oauth和oauth-plugin,但我从来没有取得任何成功的结果。 我用google搜索“oauth test”的两个测试消费者给我看了同样的东西: http://term.ie/oauth/example/client.php http://dev.k42b3.com/index.php/oauth/consumer

我正在使用设计1.2.rc,但我在Application和Oauth控制器中都被skip_before_filter :authenticate_user!禁用了。

0 个答案:

没有答案