开发者

Generating oauth_signature for Netflix

开发者 https://www.devze.com 2023-03-05 23:05 出处:网络
I am trying to generate an oauth signature for use with Netflix. I have been following their API documentation but have issues when they get to the line that says \"If you are using a library, once yo

I am trying to generate an oauth signature for use with Netflix. I have been following their API documentation but have issues when they get to the line that says "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 exa开发者_如何学Gomples."

I can create my base string and have my shared secret but can not figure out how to use the Oauth gem to generate a signature.

Any help would be great.


I ended up creating the Oauth signature by hand instead of using the 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


Have you looked at the omniauth strategy for tips? https://github.com/spagalloco/omniauth-netflix/blob/master/lib/omniauth/strategies/netflix.rb -- the beauty of open source..


Do you mean this:

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消