为Netflix生成oauth_signature

时间:2011-05-12 14:21:45

标签: ruby-on-rails-3 netflix

我正在尝试生成一个用于Netflix的oauth签名。我一直在关注他们的API文档,但是当他们到达“If you are using a library, once you have created your base string, it is easy to generate the signature. You pass your base string and your shared secret to a function and get the signature back. See the OAuth Code Page for examples”行时会遇到问题。

我可以创建我的基本字符串并拥有我的共享秘密,但无法弄清楚如何使用Oauth gem生成签名。

任何帮助都会很棒。

3 个答案:

答案 0 :(得分:2)

我最终手工创建Oauth签名而不是使用gem:

  plain_url = "#{NETFLIX_PUBLIC_URL}"+"#{NETFLIX_TOKEN_ACCESS}"


   latest_time = "#{Time.now.to_i}"
   nonce = rand(1_000_000)
   token_string="oauth_consumer_key=#{NETFLIX_KEY}&oauth_nonce=#{nonce}&oauth_signature_method=HMAC-SHA1&oauth_timestamp=#{latest_time}" +
       "&oauth_token=#{oauth_token}&oauth_version=1.0"

   encoded_string = CGI.escape(token_string)
   encoded_url = CGI.escape(plain_url)
   signature_string=  "GET&"+encoded_url+"&"+encoded_string
   puts "signature string is " + signature_string

   signature_key = "#{NETFLIX_SECRET}&#{token_secret}"

   signature = Base64.encode64(HMAC::SHA1.digest( signature_key,signature_string)).chomp.gsub(/\n/,'')

   encoded_signature = CGI.escape(signature)
   call = plain_url + "?" + token_string + "&oauth_signature="+encoded_signature

答案 1 :(得分:0)

你有没有看过omniauth策略的提示? https://github.com/spagalloco/omniauth-netflix/blob/master/lib/omniauth/strategies/netflix.rb - 开源之美..

答案 2 :(得分:0)

你的意思是:

OAuth::Signature.signature_base_string(request, options = {}, &block)

http://www.rubydoc.info/gems/oauth/0.4.7/OAuth/Signature