为 Netflix 生成 oauth_signature [英] Generating oauth_signature for Netflix

查看:69
本文介绍了为 Netflix 生成 oauth_signature的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成用于 Netflix 的 oauth 签名.我一直在关注他们的 API 文档,但是当他们到达如果您使用一个库,一旦您创建了基本字符串,就可以轻松生成签名.您将基本字符串和共享机密传递给函数并取回签名.有关示例,请参阅 OAuth 代码页."

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

我可以创建我的基本字符串并拥有我的共享秘密,但不知道如何使用 Oauth gem 生成签名.

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.

任何帮助都会很棒.

推荐答案

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

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

这篇关于为 Netflix 生成 oauth_signature的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆