Bryan
Bryan

Reputation: 41

Generating oauth_signature for Netflix

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 examples."

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.

Upvotes: 4

Views: 1129

Answers (3)

s-cho-m
s-cho-m

Reputation: 1027

Do you mean this:

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

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

Upvotes: 0

Liz Derr
Liz Derr

Reputation: 31

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

Upvotes: 2

Rabbott
Rabbott

Reputation: 4332

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..

Upvotes: 0

Related Questions