在OAuth哈希中访问@consumer

时间:2014-05-14 01:30:35

标签: ruby-on-rails ruby-on-rails-4 omniauth

尝试使用此oauth哈希获取网站

authinfo = #<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash secret="0bh6vtu1kz00dw5twf1ojt4a1o6d0pb8" token="me4vyzf3zzp6shl9t7srclk2uvb2pomr"> extra=#<OmniAuth::AuthHash access_token=#<OAuth::AccessToken:0x007fbfb44f78a8 @token="me4vyzf3zzp6shl9t7srclk2uvb2pomr", @secret="0bh6vtu1kz00dw5twf1ojt4a1o6d0pb8", @consumer=#<OAuth::Consumer:0x007fbfb09332b8 @key="zlbz0tbpgexpxyrn342y5ccqkg0m8owc", @secret="10ad6du2udy5qh71j82xkhmf6pxb1zeh", @options={:signature_method=>"HMAC-SHA1", :request_token_path=>"/oauth/initiate", :authorize_path=>"/su", :access_token_path=>"/oauth/token", :proxy=>nil, :scheme=>:header, :http_method=>:post, :oauth_version=>"1.0", :site=>"https://store.windowfarms.com"}, @uri=#<URI::HTTPS:0x007fbfb44f7060 URL:https://store.windowfarms.com>, @http=#<Net::HTTP store.windowfarms.com:443 open=false>, @http_method=:post>, @params={:oauth_token=>"me4vyzf3zzp6shl9t7srclk2uvb2pomr", "oauth_token"=>"me4vyzf3zzp6shl9t7srclk2uvb2pomr", :oauth_token_secret=>"0bh6vtu1kz00dw5twf1ojt4a1o6d0pb8", "oauth_token_secret"=>"0bh6vtu1kz00dw5twf1ojt4a1o6d0pb8"}, @response=#<Net::HTTPInternalServerError 500 Internal Server Error readbody=true>>> info=#<OmniAuth::AuthHash::InfoHash email=nil first_name=nil last_name=nil> provider="magento" uid=0>

试过这个而且没有运气,未定义[]为nil Class

auth_info["extra"]["access_token"]["consumer"]["options"]["site"]

尝试并失败。

auth_info["extra"]["access_token"]["@consumer"]["options"]["site"]

我怎样才能访问@consumer - &gt; @options

1 个答案:

答案 0 :(得分:0)

看起来访问令牌不是哈希对象,并将consumer属性实现为reader方法。看起来消费者对象也将选项公开为方法。我猜这样的事情可以让你访问:

auth_info["extra"]["access_token"].consumer.options["site"]