加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 为Netflix生成oauth_signature

发布时间:2020-12-17 02:10:59 所属栏目:百科 来源:网络整理
导读:我正在尝试生成一个用于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
我正在尝试生成一个用于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生成签名.

任何帮助都会很棒.

解决方法

我最终手工创建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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读